@@ -6,7 +6,6 @@ const { v4: uuidv4 } = require('uuid');
6
6
const assert = require ( 'assert' ) ;
7
7
const promiseRetry = require ( 'promise-retry' ) ;
8
8
const Locator = require ( '../locator' ) ;
9
- const store = require ( '../store' ) ;
10
9
const recorder = require ( '../recorder' ) ;
11
10
const stringIncludes = require ( '../assert/include' ) . includes ;
12
11
const { urlEquals } = require ( '../assert/equal' ) ;
@@ -2679,6 +2678,7 @@ class Playwright extends Helper {
2679
2678
*/
2680
2679
async waitForText ( text , sec = null , context = null ) {
2681
2680
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2681
+ const errorMessage = `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec.` ;
2682
2682
let waiter ;
2683
2683
2684
2684
const contextObject = await this . _getContext ( ) ;
@@ -2689,18 +2689,21 @@ class Playwright extends Helper {
2689
2689
try {
2690
2690
await contextObject . locator ( `${ locator . isCustom ( ) ? `${ locator . type } =${ locator . value } ` : locator . simplify ( ) } >> text=${ text } ` ) . first ( ) . waitFor ( { timeout : waitTimeout , state : 'visible' } ) ;
2691
2691
} 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 } ` ) ;
2694
2693
}
2695
2694
}
2696
2695
2697
2696
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
+ }
2704
2707
}
2705
2708
} else {
2706
2709
// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
@@ -2714,7 +2717,7 @@ class Playwright extends Helper {
2714
2717
count += 1000 ;
2715
2718
} while ( count <= waitTimeout ) ;
2716
2719
2717
- if ( ! waiter ) throw new Error ( `Text " ${ text } " was not found on page after ${ waitTimeout / 1000 } sec ` ) ;
2720
+ if ( ! waiter ) throw new Error ( `${ errorMessage } ` ) ;
2718
2721
}
2719
2722
}
2720
2723
0 commit comments