I am waiting for a url https://www.test.com/test/test I’m using this.page.waitForUrl("**test.com/test**)
but that’s giving me an error. Is that the right way to wait for that url?
The test fails there saying that it can’t find the url. The regular expression is the wrong one even though it redirected to that url.
3
You might try one of the following:
this.page.waitForUrl("**/*.test.com/test/**");
this.page.waitForUrl("**/www.test.com/test/**");
this.page.waitForUrl(/test.com/test//);
The wildcard *
(one path chunk) and **
(many path chunks) parts should be within /
and .
delimiters. This isn’t a regex, it’s a glob-style URL pattern.
Here’s a runnable, reproducible example:
const playwright = require("playwright"); // ^1.46.1
let browser;
(async () => {
const url = "https://en.wikipedia.org/wiki/Quicksort";
browser = await playwright.chromium.launch({headless: false});
const page = await browser.newPage();
await page.goto(url, {waitUntil: "commit"});
await page.waitForURL("**/*.wikipedia.org/wiki/**");
await page.waitForURL("**/en.wikipedia.org/wiki/**");
// or use a regex:
await page.waitForURL(/.wikipedia.org/wiki//);
// These fail:
// await page.waitForURL("**/*.wikipedia.org/wiki**");
// await page.waitForURL("**/.wikipedia.org/wiki/**");
// await page.waitForURL("**.wikipedia.org/wiki/**");
// await page.waitForURL("**wikipedia.org/wiki/**");
})()
.catch(err => console.error(err))
.finally(() => browser?.close());
If your page opens in a new tab, capture the tab to a page object, then apply the above on the new page.
3