MCPcopy
hub / github.com/vercel/next.js / waitForElementByCss

Method waitForElementByCss

test/lib/browsers/playwright.ts:526–563  ·  view source on GitHub ↗
(selector: string, opts: number | ElementByCssOpts = {})

Source from the content-addressed store, hash-verified

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 () => {

Callers 15

elementByCssMethod · 0.95
elementByCssInstantMethod · 0.95
goFromHomeToAnotherFunction · 0.80
goFromAnotherToHomeFunction · 0.80
navigateTestFunction · 0.80
runTestsFunction · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80
index.test.tsFile · 0.80
runTestsFunction · 0.80
index.test.tsFile · 0.80
runTestsFunction · 0.80

Calls 3

startChainMethod · 0.95
wrapElementMethod · 0.95
startsWithMethod · 0.80

Tested by 15

goFromHomeToAnotherFunction · 0.64
goFromAnotherToHomeFunction · 0.64
navigateTestFunction · 0.64
runTestsFunction · 0.64
runTestsFunction · 0.64
runTestsFunction · 0.64
navigateToFunction · 0.64
getAnnouncedTitleFunction · 0.64
runTestsFunction · 0.64
runTestsFunction · 0.64
showsErrorFunction · 0.64
noErrorFunction · 0.64