| 524 | } |
| 525 | |
| 526 | waitForElementByCss(selector: string, opts: number | ElementByCssOpts = {}) { |
| 527 | const { |
| 528 | timeout = 10_000, |
| 529 | waitUntil = 'load', // TODO: we should get rid of this and fix the tests that implicitly rely on it |
| 530 | // Selected elements may be in a completed boundary that React hasn't revealed yet. |
| 531 | // We almost always want to wait for the reveal. |
| 532 | // This matches Playwright's default behavior. |
| 533 | // We don't care about visibility of metadata tags. |
| 534 | // Can hopefully be dropped if https://github.com/microsoft/playwright/pull/37265 is accepted |
| 535 | state = selector.startsWith('base') || |
| 536 | selector.startsWith('link') || |
| 537 | selector.startsWith('meta') || |
| 538 | selector.startsWith('script') || |
| 539 | selector.startsWith('source') || |
| 540 | selector.startsWith('style') || |
| 541 | selector.startsWith('title') |
| 542 | ? 'attached' |
| 543 | : 'visible', |
| 544 | } = typeof opts === 'number' ? { timeout: opts } : opts |
| 545 | |
| 546 | return this.startChain(async () => { |
| 547 | const el = await page.waitForSelector(selector, { |
| 548 | timeout, |
| 549 | state, |
| 550 | }) |
| 551 | if (waitUntil !== false) { |
| 552 | // it seems selenium waits longer and tests rely on this behavior |
| 553 | // so we wait for the load event fire before returning |
| 554 | await page.waitForLoadState(waitUntil) |
| 555 | } |
| 556 | return this.wrapElement( |
| 557 | // Playwright has `null` as a possible return type in case `state` is `detached`, |
| 558 | // but we don't allow passing that here, so we can assume it's non-null |
| 559 | el!, |
| 560 | selector |
| 561 | ) |
| 562 | }) |
| 563 | } |
| 564 | |
| 565 | waitForCondition(snippet: string, timeout?: number) { |
| 566 | return this.startOrPreserveChain(async () => { |