Playwright: How to check with considering URL Params

The thing is that my website redirects you to this URL: localhost:3000/home?cityId=... I want to just check if the first part is /home and ignore the url param. How can I do that with Playwright? Current code which not works:
await page.waitForURL("**/home");

expect(page.url()).toBe("http://localhost:3000/home");
await page.waitForURL("**/home");

expect(page.url()).toBe("http://localhost:3000/home");
Solution:
yeah, bro, nvm, thank you much for your help. I now did it like this.
await expect(page).toHaveURL(/^http:\/\/localhost:3000\/home(\?.*)?$/);
await expect(page).toHaveURL(/^http:\/\/localhost:3000\/home(\?.*)?$/);
...
Jump to solution
5 Replies
yanuu :)
yanuu :)•10mo ago
you could use .toContainText(), according to docs
FleetAdmiralJakob 🗕 🗗 🗙
but not for the url right? This requires a locator to an element. I cannot use the toContainText() thing on urls
yanuu :)
yanuu :)•10mo ago
page.url() returns a string, so i don't see why not honestly I don't know much about playwright, but from what I'm reading, .toContainText() should work fine so
expect(page.url()).toContainText("http://localhost:3000/home")
expect(page.url()).toContainText("http://localhost:3000/home")
Solution
FleetAdmiralJakob 🗕 🗗 🗙
yeah, bro, nvm, thank you much for your help. I now did it like this.
await expect(page).toHaveURL(/^http:\/\/localhost:3000\/home(\?.*)?$/);
await expect(page).toHaveURL(/^http:\/\/localhost:3000\/home(\?.*)?$/);
Want results from more Discord servers?
Add your server