Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3541,23 +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
.waitForURL(
url => {
const currUrl = decodeURIComponent(window.location.href)
return currUrl.indexOf(url) > -1
},
urlPart,
expectedUrl,
{ timeout: waitTimeout },
)
.catch(async e => {
const currUrl = await this._getPageUrl() // Required because the waitForFunction can't return data.
const currUrl = await this._getPageUrl()
if (/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
}
Expand Down
19 changes: 12 additions & 7 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading