@@ -2380,7 +2380,23 @@ class Playwright extends Helper {
2380
2380
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2381
2381
locator = new Locator ( locator , 'css' ) ;
2382
2382
const context = await this . _getContext ( ) ;
2383
- const waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'visible' } ) ;
2383
+ let waiter ;
2384
+ let count = 0 ;
2385
+
2386
+ // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2387
+ if ( this . frame ) {
2388
+ do {
2389
+ waiter = await this . frame . locator ( buildLocatorString ( locator ) ) . first ( ) . isVisible ( ) ;
2390
+ await this . wait ( 1 ) ;
2391
+ count += 1000 ;
2392
+ if ( waiter ) break ;
2393
+ } while ( count <= waitTimeout ) ;
2394
+
2395
+ if ( ! waiter ) throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec.` ) ;
2396
+ return ;
2397
+ }
2398
+
2399
+ waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'visible' } ) ;
2384
2400
return waiter . catch ( ( err ) => {
2385
2401
throw new Error ( `element (${ locator . toString ( ) } ) still not visible after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2386
2402
} ) ;
@@ -2393,7 +2409,23 @@ class Playwright extends Helper {
2393
2409
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2394
2410
locator = new Locator ( locator , 'css' ) ;
2395
2411
const context = await this . _getContext ( ) ;
2396
- const waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'hidden' } ) ;
2412
+ let waiter ;
2413
+ let count = 0 ;
2414
+
2415
+ // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2416
+ if ( this . frame ) {
2417
+ do {
2418
+ waiter = await this . frame . locator ( buildLocatorString ( locator ) ) . first ( ) . isHidden ( ) ;
2419
+ await this . wait ( 1 ) ;
2420
+ count += 1000 ;
2421
+ if ( waiter ) break ;
2422
+ } while ( count <= waitTimeout ) ;
2423
+
2424
+ if ( ! waiter ) throw new Error ( `element (${ locator . toString ( ) } ) still visible after ${ waitTimeout / 1000 } sec.` ) ;
2425
+ return ;
2426
+ }
2427
+
2428
+ waiter = context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'hidden' } ) ;
2397
2429
return waiter . catch ( ( err ) => {
2398
2430
throw new Error ( `element (${ locator . toString ( ) } ) still visible after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2399
2431
} ) ;
@@ -2406,6 +2438,23 @@ class Playwright extends Helper {
2406
2438
const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout ;
2407
2439
locator = new Locator ( locator , 'css' ) ;
2408
2440
const context = await this . _getContext ( ) ;
2441
+
2442
+ let waiter ;
2443
+ let count = 0 ;
2444
+
2445
+ // we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2446
+ if ( this . frame ) {
2447
+ do {
2448
+ waiter = await this . frame . locator ( buildLocatorString ( locator ) ) . first ( ) . isHidden ( ) ;
2449
+ await this . wait ( 1 ) ;
2450
+ count += 1000 ;
2451
+ if ( waiter ) break ;
2452
+ } while ( count <= waitTimeout ) ;
2453
+
2454
+ if ( ! waiter ) throw new Error ( `element (${ locator . toString ( ) } ) still not hidden after ${ waitTimeout / 1000 } sec.` ) ;
2455
+ return ;
2456
+ }
2457
+
2409
2458
return context . waitForSelector ( buildLocatorString ( locator ) , { timeout : waitTimeout , state : 'hidden' } ) . catch ( ( err ) => {
2410
2459
throw new Error ( `element (${ locator . toString ( ) } ) still not hidden after ${ waitTimeout / 1000 } sec\n${ err . message } ` ) ;
2411
2460
} ) ;
@@ -2487,12 +2536,17 @@ class Playwright extends Helper {
2487
2536
} else {
2488
2537
// we have this as https://github.com/microsoft/playwright/issues/26829 is not yet implemented
2489
2538
if ( this . frame ) {
2490
- const { setTimeout } = require ( 'timers/promises' ) ;
2491
- await setTimeout ( waitTimeout ) ;
2492
- waiter = await this . frame . locator ( `:has-text('${ text } ')` ) . first ( ) . isVisible ( ) ;
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
+
2493
2546
if ( ! waiter ) throw new Error ( `Text "${ text } " was not found on page after ${ waitTimeout / 1000 } sec` ) ;
2494
2547
return ;
2495
2548
}
2549
+
2496
2550
waiter = contextObject . waitForFunction ( text => document . body && document . body . innerText . indexOf ( text ) > - 1 , text , { timeout : waitTimeout } ) ;
2497
2551
}
2498
2552
return waiter . catch ( ( err ) => {
0 commit comments