diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 5ab67f98e..eb109eb08 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -3541,27 +3541,28 @@ class Playwright extends Helper { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout const baseUrl = this.options.url + let expectedUrl = urlPart if (urlPart.indexOf('http') < 0) { - urlPart = baseUrl + urlPart + expectedUrl = baseUrl + urlPart } - return this.page - .waitForFunction( - urlPart => { - const currUrl = decodeURIComponent(decodeURIComponent(decodeURIComponent(window.location.href))) - return currUrl.indexOf(urlPart) > -1 - }, - urlPart, + try { + await this.page.waitForURL( + url => url.href.includes(expectedUrl), { timeout: waitTimeout }, ) - .catch(async e => { - const currUrl = await this._getPageUrl() // Required because the waitForFunction can't return data. - if (/Timeout/i.test(e.message)) { - throw new Error(`expected url to be ${urlPart}, but found ${currUrl}`) + } catch (e) { + const currUrl = await this._getPageUrl() + if (/Timeout/i.test(e.message)) { + if (!currUrl.includes(expectedUrl)) { + throw new Error(`expected url to be ${expectedUrl}, but found ${currUrl}`) } else { - throw e + throw new Error(`expected url not loaded, error message: ${e.message}`) } - }) + } else { + throw e + } + } } /** diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 6ed5f1857..fa96c9bbc 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -2451,23 +2451,28 @@ class Puppeteer extends Helper { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout const baseUrl = this.options.url + let expectedUrl = urlPart if (urlPart.indexOf('http') < 0) { - urlPart = baseUrl + urlPart + expectedUrl = baseUrl + urlPart } return this.page .waitForFunction( - urlPart => { - const currUrl = decodeURIComponent(decodeURIComponent(decodeURIComponent(window.location.href))) - return currUrl.indexOf(urlPart) > -1 + url => { + const currUrl = decodeURIComponent(window.location.href) + return currUrl.indexOf(url) > -1 }, { timeout: waitTimeout }, - urlPart, + expectedUrl, ) .catch(async e => { - const currUrl = await this._getPageUrl() // Required because the waitForFunction can't return data. + const currUrl = await this._getPageUrl() if (/Waiting failed/i.test(e.message) || /failed: timeout/i.test(e.message)) { - throw new Error(`expected url to be ${urlPart}, but found ${currUrl}`) + if (!currUrl.includes(expectedUrl)) { + throw new Error(`expected url to be ${expectedUrl}, but found ${currUrl}`) + } else { + throw new Error(`expected url not loaded, error message: ${e.message}`) + } } else { throw e }