Skip to content

feat(api): introduce locator.waitFor#9200

Merged
pavelfeldman merged 1 commit into
microsoft:masterfrom
pavelfeldman:locator_wait_for
Sep 28, 2021
Merged

feat(api): introduce locator.waitFor#9200
pavelfeldman merged 1 commit into
microsoft:masterfrom
pavelfeldman:locator_wait_for

Conversation

@pavelfeldman
Copy link
Copy Markdown
Member

@pavelfeldman pavelfeldman commented Sep 28, 2021

Fixes #8577

Comment thread src/client/locator.ts Outdated
Comment thread tests/page/locator-misc-2.spec.ts
@pavelfeldman pavelfeldman merged commit 2b055b3 into microsoft:master Sep 28, 2021
sidharthv96 added a commit to sidharthv96/playwright that referenced this pull request Oct 1, 2021
* upstream/master: (21 commits)
  fix(test runner): do not write missing snapshot until the last retry (microsoft#9246)
  feat(reporters): Add error position to JSON Report (microsoft#9151)
  feat(fetch): import/export storageState (microsoft#9244)
  fix: allow binary response interception (microsoft#9236)
  test(cookies): add a test for SameSite=None cookies (microsoft#9242)
  feat(webkit): roll WebKit to 1550 (microsoft#9239)
  test: add test for downloading PDF files (microsoft#9235)
  fix: leaking route handlers when times is used in Page.route (microsoft#9234)
  chore: upgrade commander.js to version 8 (microsoft#9230)
  feat(fetch): store cookies between requests (microsoft#9221)
  fix(selenium connect): register in gracefullyCloseAll for driver cleanup (microsoft#9218)
  fix(toBeHidden): return true to missing elements (microsoft#9205)
  chore: fix PlaywrightClient disconnection logic (microsoft#9149)
  fix(expect): beautiful expect stacks (microsoft#9204)
  feat(fetch): support ignoreHTTPSErrors option (microsoft#9206)
  feat(api): introduce locator.waitFor (microsoft#9200)
  feat(fetch): send Playwright as default user-agent for global fetch (microsoft#9195)
  feat(test runner): collect test error from worker teardown (microsoft#9190)
  test: add tests for Cross-Origin-Opener-Policy navigation (microsoft#9184)
  test: get response body for COOP responses (microsoft#9196)
  ...
sidharthv96 added a commit to sidharthv96/playwright that referenced this pull request Oct 1, 2021
…tionWithBaseChange

* upstream/master: (21 commits)
  fix(test runner): do not write missing snapshot until the last retry (microsoft#9246)
  feat(reporters): Add error position to JSON Report (microsoft#9151)
  feat(fetch): import/export storageState (microsoft#9244)
  fix: allow binary response interception (microsoft#9236)
  test(cookies): add a test for SameSite=None cookies (microsoft#9242)
  feat(webkit): roll WebKit to 1550 (microsoft#9239)
  test: add test for downloading PDF files (microsoft#9235)
  fix: leaking route handlers when times is used in Page.route (microsoft#9234)
  chore: upgrade commander.js to version 8 (microsoft#9230)
  feat(fetch): store cookies between requests (microsoft#9221)
  fix(selenium connect): register in gracefullyCloseAll for driver cleanup (microsoft#9218)
  fix(toBeHidden): return true to missing elements (microsoft#9205)
  chore: fix PlaywrightClient disconnection logic (microsoft#9149)
  fix(expect): beautiful expect stacks (microsoft#9204)
  feat(fetch): support ignoreHTTPSErrors option (microsoft#9206)
  feat(api): introduce locator.waitFor (microsoft#9200)
  feat(fetch): send Playwright as default user-agent for global fetch (microsoft#9195)
  feat(test runner): collect test error from worker teardown (microsoft#9190)
  test: add tests for Cross-Origin-Opener-Policy navigation (microsoft#9184)
  test: get response body for COOP responses (microsoft#9196)
  ...
@Phonesis
Copy link
Copy Markdown

Is this now live? I don't see a waitFor() option on my locators with 1.15.2

@yury-s
Copy link
Copy Markdown
Member

yury-s commented Oct 12, 2021

I will be released in 1.16 as 1.15 api is already published.

@Phonesis
Copy link
Copy Markdown

@yury-s Thanks for update. Out of interest, will this waitFor() function support options for timeout and state? I am hoping to do something like this and call it via a page object:

  async isElementVisible(elementLocator: Locator, waitTime: number = 3000): Promise<boolean> {
    try {
      await elementLocator.waitFor({ 
        state: 'visible',
        timeout: waitTime,
      });
    }
    catch {
      return false;
    }
    return true;
  }

@yury-s
Copy link
Copy Markdown
Member

yury-s commented Oct 13, 2021

Out of interest, will this waitFor() function support options for timeout and state?

Yes, it will support both.

It's already available in @next version of playwright, you can give it a try with npm i playwright@next.

@sarweshkumar2018
Copy link
Copy Markdown

How to handle if the locator returns more than one elements.
await this.page.locator('[aria-label="bene"]').waitFor();

await this.page.locator('[aria-label="bene"]:first-child').waitFor() --- is NOT working

@xyide
Copy link
Copy Markdown

xyide commented Mar 9, 2024

How to handle if the locator returns more than one elements.

I don't think it would be necessary to handle this case. If any element with a given selector us visible, then naturally the first-child is visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Extend locator api with functions like waitForSelector()

6 participants