Deal with multiple redirections

230 views Asked by At

I need a playwright test for a login flow that behaves like this:

  1. I'm in the page login form of Server 2, where I fill the form and click Sign In which triggers a post request to Server 2 url /login
  2. Server 2 returns 200 for /login url with a html response.
  3. Page loads and a javascript code automatically triggers a navigation to Server 1 url /signin-saml.
  4. Request to /signin-saml is executed and Server 1 returns 302 with location to Server 1 url /Account/ExternalLoginCallback.
  5. /Account/ExternalLoginCallback must load correctly including some fields.

I have tried different ways to get a 100% reliable test without luck so far. The test fails at different navigation points, saying that the navigation didn't happen. I have tried, for example, 3 await waitForUrl statements in a row playing with the timeouts and waitUntil arguments, and also a waitForTimeout using a long enough time followed by a waitForUrl(/Account/ExternalLoginCallback). I haven't tried anything with waitForNavigation since it appears as deprecated in the current version of playwright that I'm using.

I need a way to test the described scenario with a reliable test. What is the best way to do that?

Thank you in advance

1

There are 1 answers

0
Adrian Leon On BEST ANSWER

Closing as I could find a solution. Based on the answer of this question, I changed the await waitForUrl(...) statements for an await Promise.all(...) passing all the awaits as arguments and also, added a delay to the click event before the navigation to make sure the navigations didn't occur before waiting for them.