@@ -6,7 +6,6 @@ const { v4: uuidv4 } = require('uuid');
66const assert = require ( 'assert' ) ;
77const promiseRetry = require ( 'promise-retry' ) ;
88const Locator = require ( '../locator' ) ;
9- const store = require ( '../store' ) ;
109const recorder = require ( '../recorder' ) ;
1110const stringIncludes = require ( '../assert/include' ) . includes ;
1211const { urlEquals } = require ( '../assert/equal' ) ;
@@ -2679,6 +2678,7 @@ class Playwright extends Helper {
26792678 */
26802679 async waitForText ( text , sec = null , context = null ) {
26812680 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2681+ const errorMessage = `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec.` ;
26822682 let waiter ;
26832683
26842684 const contextObject = await this . _getContext ( ) ;
@@ -2689,18 +2689,21 @@ class Playwright extends Helper {
26892689 try {
26902690 await contextObject . locator ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } >> text=${ text } ` ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'visible' } ) ;
26912691 } catch ( e ) {
2692- console . log ( e ) ;
2693- throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec\n${ e . message } ` ) ;
2692+ throw new Error ( `${ errorMessage } \n${ e . message } ` ) ;
26942693 }
26952694 }
26962695
26972696 if ( locator . isXPath ( ) ) {
2698- waiter = contextObject . waitForFunction ( ( [ locator , text , $XPath ] ) => {
2699- eval ( $XPath ) ; // eslint-disable-line no-eval
2700- const el = $XPath ( null , locator ) ;
2701- if ( ! el . length ) return false ;
2702- return el [ 0 ] . innerText . indexOf ( text ) > - 1 ;
2703- } , [ locator . value , text , $XPath . toString ( ) ] , { timeout : waitTimeout } ) ;
2697+ try {
2698+ await contextObject . waitForFunction ( ( [ locator , text , $XPath ] ) => {
2699+ eval ( $XPath ) ; // eslint-disable-line no-eval
2700+ const el = $XPath ( null , locator ) ;
2701+ if ( ! el . length ) return false ;
2702+ return el [ 0 ] . innerText . indexOf ( text ) > - 1 ;
2703+ } , [ locator . value , text , $XPath . toString ( ) ] , { timeout : waitTimeout } ) ;
2704+ } catch ( e ) {
2705+ throw new Error ( `${ errorMessage } \n${ e . message } ` ) ;
2706+ }
27042707 }
27052708 } else {
27062709 // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
@@ -2714,7 +2717,7 @@ class Playwright extends Helper {
27142717 count += 1000 ;
27152718 } while ( count <= waitTimeout ) ;
27162719
2717- if ( ! waiter ) throw new Error ( `Text " ${ text } " was not found on page after ${ waitTimeout / 1000 } sec ` ) ;
2720+ if ( ! waiter ) throw new Error ( `${ errorMessage } ` ) ;
27182721 }
27192722 }
27202723
0 commit comments