@@ -2365,10 +2365,11 @@ class Playwright extends Helper {
2365
2365
locator = new Locator ( locator , 'css' ) ;
2366
2366
2367
2367
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
+ }
2372
2373
}
2373
2374
2374
2375
/**
@@ -2380,10 +2381,10 @@ class Playwright extends Helper {
2380
2381
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2381
2382
locator = new Locator ( locator , 'css' ) ;
2382
2383
const context = await this . _getContext ( ) ;
2383
- let waiter ;
2384
2384
let count = 0 ;
2385
2385
2386
2386
// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2387
+ let waiter ;
2387
2388
if ( this . frame ) {
2388
2389
do {
2389
2390
waiter = await this . frame . locator ( buildLocatorString ( locator ) ) . first ( ) . isVisible ( ) ;
@@ -2393,13 +2394,13 @@ class Playwright extends Helper {
2393
2394
} while ( count <= waitTimeout ) ;
2394
2395
2395
2396
if ( ! waiter ) throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec.` ) ;
2396
- return ;
2397
2397
}
2398
2398
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
+ }
2403
2404
}
2404
2405
2405
2406
/**
@@ -2425,10 +2426,11 @@ class Playwright extends Helper {
2425
2426
return ;
2426
2427
}
2427
2428
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
+ }
2432
2434
}
2433
2435
2434
2436
/**
@@ -2438,7 +2440,6 @@ class Playwright extends Helper {
2438
2440
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2439
2441
locator = new Locator ( locator , 'css' ) ;
2440
2442
const context = await this . _getContext ( ) ;
2441
-
2442
2443
let waiter ;
2443
2444
let count = 0 ;
2444
2445
@@ -2455,7 +2456,7 @@ class Playwright extends Helper {
2455
2456
return ;
2456
2457
}
2457
2458
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 ) => {
2459
2460
throw new Error ( `element (${ locator . toString ( ) } ) still not hidden after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2460
2461
} ) ;
2461
2462
}
@@ -2522,7 +2523,12 @@ class Playwright extends Helper {
2522
2523
if ( context ) {
2523
2524
const locator = new Locator ( context , 'css' ) ;
2524
2525
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
+ }
2526
2532
}
2527
2533
2528
2534
if ( locator . isXPath ( ) ) {
@@ -2535,23 +2541,17 @@ class Playwright extends Helper {
2535
2541
}
2536
2542
} else {
2537
2543
// 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 ) ;
2549
2552
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` ) ;
2551
2554
}
2552
- return waiter . catch ( ( err ) => {
2553
- throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2554
- } ) ;
2555
2555
}
2556
2556
2557
2557
/**
@@ -2710,17 +2710,21 @@ class Playwright extends Helper {
2710
2710
let waiter ;
2711
2711
const context = await this . _getContext ( ) ;
2712
2712
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
+ }
2714
2718
} else {
2715
2719
const visibleFn = function ( [ locator , $XPath ] ) {
2716
2720
eval ( $XPath ) ; // eslint-disable-line no-eval
2717
2721
return $XPath ( null , locator ) . length === 0 ;
2718
2722
} ;
2719
2723
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
+ } ) ;
2720
2727
}
2721
- return waiter . catch ( ( err ) => {
2722
- throw new Error ( `element (${ locator . toString ( ) } ) still on page after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2723
- } ) ;
2724
2728
}
2725
2729
2726
2730
async _waitForAction ( ) {
0 commit comments