File tree Expand file tree Collapse file tree 2 files changed +27
-21
lines changed
Expand file tree Collapse file tree 2 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -3541,27 +3541,28 @@ class Playwright extends Helper {
35413541 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
35423542
35433543 const baseUrl = this . options . url
3544+ let expectedUrl = urlPart
35443545 if ( urlPart . indexOf ( 'http' ) < 0 ) {
3545- urlPart = baseUrl + urlPart
3546+ expectedUrl = baseUrl + urlPart
35463547 }
35473548
3548- return this . page
3549- . waitForFunction (
3550- urlPart => {
3551- const currUrl = decodeURIComponent ( decodeURIComponent ( decodeURIComponent ( window . location . href ) ) )
3552- return currUrl . indexOf ( urlPart ) > - 1
3553- } ,
3554- urlPart ,
3549+ try {
3550+ await this . page . waitForURL (
3551+ url => url . href . includes ( expectedUrl ) ,
35553552 { timeout : waitTimeout } ,
35563553 )
3557- . catch ( async e => {
3558- const currUrl = await this . _getPageUrl ( ) // Required because the waitForFunction can't return data.
3559- if ( / T i m e o u t / i. test ( e . message ) ) {
3560- throw new Error ( `expected url to be ${ urlPart } , but found ${ currUrl } ` )
3554+ } catch ( e ) {
3555+ const currUrl = await this . _getPageUrl ( )
3556+ if ( / T i m e o u t / i. test ( e . message ) ) {
3557+ if ( ! currUrl . includes ( expectedUrl ) ) {
3558+ throw new Error ( `expected url to be ${ expectedUrl } , but found ${ currUrl } ` )
35613559 } else {
3562- throw e
3560+ throw new Error ( `expected url not loaded, error message: ${ e . message } ` )
35633561 }
3564- } )
3562+ } else {
3563+ throw e
3564+ }
3565+ }
35653566 }
35663567
35673568 /**
Original file line number Diff line number Diff line change @@ -2451,23 +2451,28 @@ class Puppeteer extends Helper {
24512451 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
24522452
24532453 const baseUrl = this . options . url
2454+ let expectedUrl = urlPart
24542455 if ( urlPart . indexOf ( 'http' ) < 0 ) {
2455- urlPart = baseUrl + urlPart
2456+ expectedUrl = baseUrl + urlPart
24562457 }
24572458
24582459 return this . page
24592460 . waitForFunction (
2460- urlPart => {
2461- const currUrl = decodeURIComponent ( decodeURIComponent ( decodeURIComponent ( window . location . href ) ) )
2462- return currUrl . indexOf ( urlPart ) > - 1
2461+ url => {
2462+ const currUrl = decodeURIComponent ( window . location . href )
2463+ return currUrl . indexOf ( url ) > - 1
24632464 } ,
24642465 { timeout : waitTimeout } ,
2465- urlPart ,
2466+ expectedUrl ,
24662467 )
24672468 . catch ( async e => {
2468- const currUrl = await this . _getPageUrl ( ) // Required because the waitForFunction can't return data.
2469+ const currUrl = await this . _getPageUrl ( )
24692470 if ( / W a i t i n g f a i l e d / i. test ( e . message ) || / f a i l e d : t i m e o u t / i. test ( e . message ) ) {
2470- throw new Error ( `expected url to be ${ urlPart } , but found ${ currUrl } ` )
2471+ if ( ! currUrl . includes ( expectedUrl ) ) {
2472+ throw new Error ( `expected url to be ${ expectedUrl } , but found ${ currUrl } ` )
2473+ } else {
2474+ throw new Error ( `expected url not loaded, error message: ${ e . message } ` )
2475+ }
24712476 } else {
24722477 throw e
24732478 }
You can’t perform that action at this time.
0 commit comments