@@ -13,7 +13,18 @@ import output from '../output.js'
1313const { debug } = output
1414import { empty } from '../assert/empty.js'
1515import { truth } from '../assert/truth.js'
16- import { xpathLocator , fileExists , decodeUrl , chunkArray , convertCssPropertiesToCamelCase , screenshotOutputFolder , getNormalizedKeyAttributeValue , modifierKeys } from '../utils.js'
16+ import {
17+ xpathLocator ,
18+ fileExists ,
19+ decodeUrl ,
20+ chunkArray ,
21+ convertCssPropertiesToCamelCase ,
22+ screenshotOutputFolder ,
23+ getNormalizedKeyAttributeValue ,
24+ modifierKeys ,
25+ normalizePath ,
26+ resolveUrl ,
27+ } from '../utils.js'
1728import { isColorProperty , convertColorToRGBA } from '../colorUtils.js'
1829import ElementNotFound from './errors/ElementNotFound.js'
1930import ConnectionRefused from './errors/ConnectionRefused.js'
@@ -1854,7 +1865,7 @@ class WebDriver extends Helper {
18541865 const currentUrl = await this . browser . getUrl ( )
18551866 const baseUrl = this . options . url || 'http://localhost'
18561867 const actualPath = new URL ( currentUrl , baseUrl ) . pathname
1857- return equals ( 'url path' ) . assert ( path , actualPath )
1868+ return equals ( 'url path' ) . assert ( normalizePath ( path ) , normalizePath ( actualPath ) )
18581869 }
18591870
18601871 /**
@@ -1864,7 +1875,7 @@ class WebDriver extends Helper {
18641875 const currentUrl = await this . browser . getUrl ( )
18651876 const baseUrl = this . options . url || 'http://localhost'
18661877 const actualPath = new URL ( currentUrl , baseUrl ) . pathname
1867- return equals ( 'url path' ) . negate ( path , actualPath )
1878+ return equals ( 'url path' ) . negate ( normalizePath ( path ) , normalizePath ( actualPath ) )
18681879 }
18691880
18701881 /**
@@ -2490,22 +2501,23 @@ class WebDriver extends Helper {
24902501 async waitInUrl ( urlPart , sec = null ) {
24912502 const client = this . browser
24922503 const aSec = sec || this . options . waitForTimeoutInSeconds
2504+ const expectedUrl = resolveUrl ( urlPart , this . options . url )
24932505 let currUrl = ''
24942506
24952507 return client
24962508 . waitUntil (
24972509 function ( ) {
24982510 return this . getUrl ( ) . then ( res => {
24992511 currUrl = decodeUrl ( res )
2500- return currUrl . indexOf ( urlPart ) > - 1
2512+ return currUrl . indexOf ( expectedUrl ) > - 1
25012513 } )
25022514 } ,
25032515 { timeout : aSec * 1000 } ,
25042516 )
25052517 . catch ( e => {
25062518 e = wrapError ( e )
25072519 if ( e . message . indexOf ( 'timeout' ) ) {
2508- throw new Error ( `expected url to include ${ urlPart } , but found ${ currUrl } ` )
2520+ throw new Error ( `expected url to include ${ expectedUrl } , but found ${ currUrl } ` )
25092521 }
25102522 throw e
25112523 } )
@@ -2516,22 +2528,47 @@ class WebDriver extends Helper {
25162528 */
25172529 async waitUrlEquals ( urlPart , sec = null ) {
25182530 const aSec = sec || this . options . waitForTimeoutInSeconds
2519- const baseUrl = this . options . url
2520- if ( urlPart . indexOf ( 'http' ) < 0 ) {
2521- urlPart = baseUrl + urlPart
2522- }
2531+ const expectedUrl = resolveUrl ( urlPart , this . options . url )
25232532 let currUrl = ''
25242533 return this . browser
25252534 . waitUntil ( function ( ) {
25262535 return this . getUrl ( ) . then ( res => {
25272536 currUrl = decodeUrl ( res )
2528- return currUrl === urlPart
2537+ return currUrl === expectedUrl
25292538 } )
25302539 } , aSec * 1000 )
25312540 . catch ( e => {
25322541 e = wrapError ( e )
25332542 if ( e . message . indexOf ( 'timeout' ) ) {
2534- throw new Error ( `expected url to be ${ urlPart } , but found ${ currUrl } ` )
2543+ throw new Error ( `expected url to be ${ expectedUrl } , but found ${ currUrl } ` )
2544+ }
2545+ throw e
2546+ } )
2547+ }
2548+
2549+ /**
2550+ * {{> waitCurrentPathEquals }}
2551+ */
2552+ async waitCurrentPathEquals ( path , sec = null ) {
2553+ const aSec = sec || this . options . waitForTimeoutInSeconds
2554+ const normalizedPath = normalizePath ( path )
2555+ const baseUrl = this . options . url || 'http://localhost'
2556+ let actualPath = ''
2557+
2558+ return this . browser
2559+ . waitUntil (
2560+ async ( ) => {
2561+ const currUrl = await this . browser . getUrl ( )
2562+ const url = new URL ( currUrl , baseUrl )
2563+ actualPath = url . pathname
2564+ return normalizePath ( actualPath ) === normalizedPath
2565+ } ,
2566+ { timeout : aSec * 1000 } ,
2567+ )
2568+ . catch ( e => {
2569+ e = wrapError ( e )
2570+ if ( e . message . indexOf ( 'timeout' ) ) {
2571+ throw new Error ( `expected path to be ${ normalizedPath } , but found ${ normalizePath ( actualPath ) } ` )
25352572 }
25362573 throw e
25372574 } )
0 commit comments