I'm writing a test with playwright and I'd like to know the most correct way to check if after a pression of a button, it emitted a redirect to the expected URL, in order to pass the test.
Any help is appreciated, thanks!
I've found this snippet:
const [request] = await Promise.all([
// Waits for the next request with the specified url
page.waitForRequest('*URL*'),
// Triggers the request
page.click('button'),
]);
but it get stucked because it first clicks on the button, the redirect happens but then it keeps waiting for the request anyway.
Will waitForNaviation() work for you?
const [response] = await Promise.all([
// Waits for the main frame navigation and returns the main resource response
page.waitForNavigation({url: '*URL*'}),
// Triggers the request
page.click('button'),
]);