@@ -27,6 +27,7 @@ import {
2727 requireWithFallback ,
2828 normalizeSpacesInString ,
2929 normalizePath ,
30+ resolveUrl ,
3031} from '../utils.js'
3132import { isColorProperty , convertColorToRGBA } from '../colorUtils.js'
3233import ElementNotFound from './errors/ElementNotFound.js'
@@ -2442,6 +2443,7 @@ class Puppeteer extends Helper {
24422443 */
24432444 async waitInUrl ( urlPart , sec = null ) {
24442445 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
2446+ const expectedUrl = resolveUrl ( urlPart , this . options . url )
24452447
24462448 return this . page
24472449 . waitForFunction (
@@ -2450,12 +2452,12 @@ class Puppeteer extends Helper {
24502452 return currUrl . indexOf ( urlPart ) > - 1
24512453 } ,
24522454 { timeout : waitTimeout } ,
2453- urlPart ,
2455+ expectedUrl ,
24542456 )
24552457 . catch ( async e => {
2456- const currUrl = await this . _getPageUrl ( ) // Required because the waitForFunction can't return data.
2458+ const currUrl = await this . _getPageUrl ( )
24572459 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 ) ) {
2458- throw new Error ( `expected url to include ${ urlPart } , but found ${ currUrl } ` )
2460+ throw new Error ( `expected url to include ${ expectedUrl } , but found ${ currUrl } ` )
24592461 } else {
24602462 throw e
24612463 }
@@ -2467,30 +2469,21 @@ class Puppeteer extends Helper {
24672469 */
24682470 async waitUrlEquals ( urlPart , sec = null ) {
24692471 const waitTimeout = sec ? sec * 1000 : this . options . waitForTimeout
2470-
2471- const baseUrl = this . options . url
2472- let expectedUrl = urlPart
2473- if ( urlPart . indexOf ( 'http' ) < 0 ) {
2474- expectedUrl = baseUrl + urlPart
2475- }
2472+ const expectedUrl = resolveUrl ( urlPart , this . options . url )
24762473
24772474 return this . page
24782475 . waitForFunction (
24792476 url => {
24802477 const currUrl = decodeURIComponent ( window . location . href )
2481- return currUrl . indexOf ( url ) > - 1
2478+ return currUrl === url
24822479 } ,
24832480 { timeout : waitTimeout } ,
24842481 expectedUrl ,
24852482 )
24862483 . catch ( async e => {
24872484 const currUrl = await this . _getPageUrl ( )
24882485 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 ) ) {
2489- if ( ! currUrl . includes ( expectedUrl ) ) {
2490- throw new Error ( `expected url to be ${ expectedUrl } , but found ${ currUrl } ` )
2491- } else {
2492- throw new Error ( `expected url not loaded, error message: ${ e . message } ` )
2493- }
2486+ throw new Error ( `expected url to be ${ expectedUrl } , but found ${ currUrl } ` )
24942487 } else {
24952488 throw e
24962489 }
0 commit comments