@@ -2365,10 +2365,11 @@ class Playwright extends Helper {
23652365 locator = new Locator ( locator , 'css' ) ;
23662366
23672367 const context = await this . _getContext ( ) ;
2368- const waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'attached' } ) ;
2369- return waiter . catch ( ( err ) => {
2370- throw new Error ( `element (${ locator . toString ( ) } ) still not present on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2371- } ) ;
2368+ try {
2369+ await context . locator ( buildLocatorString ( locator ) ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'attached' } ) ;
2370+ } catch ( e ) {
2371+ throw new Error ( `element (${ locator . toString ( ) } ) still not present on page after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2372+ }
23722373 }
23732374
23742375 /**
@@ -2380,10 +2381,10 @@ class Playwright extends Helper {
23802381 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
23812382 locator = new Locator ( locator , 'css' ) ;
23822383 const context = await this . _getContext ( ) ;
2383- let waiter ;
23842384 let count = 0 ;
23852385
23862386 // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2387+ let waiter ;
23872388 if ( this . frame ) {
23882389 do {
23892390 waiter = await this . frame . locator ( buildLocatorString ( locator ) ) . first ( ) . isVisible ( ) ;
@@ -2393,13 +2394,13 @@ class Playwright extends Helper {
23932394 } while ( count <= waitTimeout ) ;
23942395
23952396 if ( ! waiter ) throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec.` ) ;
2396- return ;
23972397 }
23982398
2399- waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'visible' } ) ;
2400- return waiter . catch ( ( err ) => {
2401- throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2402- } ) ;
2399+ try {
2400+ await context . locator ( buildLocatorString ( locator ) ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'visible' } ) ;
2401+ } catch ( e ) {
2402+ throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2403+ }
24032404 }
24042405
24052406 /**
@@ -2425,10 +2426,11 @@ class Playwright extends Helper {
24252426 return ;
24262427 }
24272428
2428- waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'hidden' } ) ;
2429- return waiter . catch ( ( err ) => {
2430- throw new Error ( `element (${ locator . toString ( ) } ) still visible after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2431- } ) ;
2429+ try {
2430+ await context . locator ( buildLocatorString ( locator ) ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'hidden' } ) ;
2431+ } catch ( e ) {
2432+ throw new Error ( `element (${ locator . toString ( ) } ) still visible after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2433+ }
24322434 }
24332435
24342436 /**
@@ -2438,7 +2440,6 @@ class Playwright extends Helper {
24382440 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
24392441 locator = new Locator ( locator , 'css' ) ;
24402442 const context = await this . _getContext ( ) ;
2441-
24422443 let waiter ;
24432444 let count = 0 ;
24442445
@@ -2455,7 +2456,7 @@ class Playwright extends Helper {
24552456 return ;
24562457 }
24572458
2458- return context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'hidden' } ) . catch ( ( err ) => {
2459+ return context . locator ( buildLocatorString ( locator ) ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'hidden' } ) . catch ( ( err ) => {
24592460 throw new Error ( `element (${ locator . toString ( ) } ) still not hidden after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
24602461 } ) ;
24612462 }
@@ -2522,7 +2523,12 @@ class Playwright extends Helper {
25222523 if ( context ) {
25232524 const locator = new Locator ( context , 'css' ) ;
25242525 if ( ! locator . isXPath ( ) ) {
2525- waiter = contextObject . waitForSelector ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } >> text=${ text } ` , { timeout : waitTimeout , state : 'visible' } ) ;
2526+ try {
2527+ await contextObject . locator ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } >> text=${ text } ` ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'visible' } ) ;
2528+ } catch ( e ) {
2529+ console . log ( e ) ;
2530+ throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2531+ }
25262532 }
25272533
25282534 if ( locator . isXPath ( ) ) {
@@ -2535,23 +2541,17 @@ class Playwright extends Helper {
25352541 }
25362542 } else {
25372543 // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2538- if ( this . frame ) {
2539- let count = 0 ;
2540- do {
2541- waiter = await this . frame . locator ( `:has-text('${ text } ')` ) . first ( ) . isVisible ( ) ;
2542- await this . wait ( 1 ) ;
2543- count += 1000 ;
2544- } while ( count <= waitTimeout ) ;
2545-
2546- if ( ! waiter ) throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec` ) ;
2547- return ;
2548- }
2544+ // eslint-disable-next-line no-lonely-if
2545+ const _contextObject = this . frame ? this . frame : contextObject ;
2546+ let count = 0 ;
2547+ do {
2548+ waiter = await _contextObject . locator ( `:has-text('${ text } ')` ) . first ( ) . isVisible ( ) ;
2549+ await this . wait ( 1 ) ;
2550+ count += 1000 ;
2551+ } while ( count <= waitTimeout ) ;
25492552
2550- waiter = contextObject . waitForFunction ( text => document . body && document . body . innerText . indexOf ( text ) > - 1 , text , { timeout : waitTimeout } ) ;
2553+ if ( ! waiter ) throw new Error ( `Text " ${ text } " was not found on page after ${ waitTimeout / 1000 } sec` ) ;
25512554 }
2552- return waiter . catch ( ( err ) => {
2553- throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2554- } ) ;
25552555 }
25562556
25572557 /**
@@ -2710,17 +2710,21 @@ class Playwright extends Helper {
27102710 let waiter ;
27112711 const context = await this . _getContext ( ) ;
27122712 if ( ! locator . isXPath ( ) ) {
2713- waiter = context . waitForSelector ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } ` , { timeout : waitTimeout , state : 'detached' } ) ;
2713+ try {
2714+ await context . locator ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } ` ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'detached' } ) ;
2715+ } catch ( e ) {
2716+ throw new Error ( `element (${ locator . toString ( ) } ) still on page after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2717+ }
27142718 } else {
27152719 const visibleFn = function ( [ locator , $XPath ] ) {
27162720 eval ( $XPath ) ; // eslint-disable-line no-eval
27172721 return $XPath ( null , locator ) . length === 0 ;
27182722 } ;
27192723 waiter = context . waitForFunction ( visibleFn , [ locator . value , $XPath . toString ( ) ] , { timeout : waitTimeout } ) ;
2724+ return waiter . catch ( ( err ) => {
2725+ throw new Error ( `element (${ locator . toString ( ) } ) still on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2726+ } ) ;
27202727 }
2721- return waiter . catch ( ( err ) => {
2722- throw new Error ( `element (${ locator . toString ( ) } ) still on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2723- } ) ;
27242728 }
27252729
27262730 async _waitForAction ( ) {
0 commit comments