I want to wait for a URL https://www.test.com/test/test in my Playwright test. I tried:
```javascript
await this.page.waitForURL("**test.com/test**");
But it gives an error, saying it can’t find the URL. It seems the regular expression or pattern is not correct, even though the page does redirect to that URL. What is the correct way to wait for this URL?
When I needed to wait for a specific page, I found that Playwright’s waitForURL works well with glob patterns. For your example:
await page.waitForURL('**/test/test');
The ** matches any protocol and domain, so you don’t need to hardcode https://www.test.com. This reliably waits for the page to navigate to the desired path.
If you want more control over matching, I usually switch to a regex:
await page.waitForURL(/https:\/\/www\.test\.com\/test\/test/);
This ensures the URL matches exactly. Regex is especially useful if query parameters may vary, or if you want to match multiple similar URLs.
I often only care about the path part of the URL and not the domain, so I do:
await page.waitForURL('**/test/test', { timeout: 5000 });
Adding a timeout is optional but handy for slower pages. This method avoids errors when the domain might change between environments like local, CI, or production.