6

How do we test SPAs which have Azure AD based authentication? When user opens the app, user is first sent to login.microsoftonline.com and on entering the user email the page redirects back to application home page. In this scenario, how do we automate using Playwright?

code_blue
  • 523
  • 2
  • 9
  • 19
  • Sorry to see no-one helped you. I have the exact same question that you did. Can you perhaps share how you solved this (if you managed to). At the moment, I am using a wait, closing the browser and reloading after the cookie is set. But it feels wrong. – onefootswill Jul 02 '21 at 07:57

1 Answers1

1

Could you elaborate a bit more on what you're looking for? The flow should look like fill credentials, login, wait for your logged_in condition, whether that be a cookie that gets set or a redirect (a simple redirect would be easy to handle). For example:

await Promise.all([
    page.fill('input[name="loginfmt"]', credentials.username),
    page.waitForURL(HOMEPAGE_URL),
]);

See page.waitForURL.

Then you can do stuff like extract the user's session for reuse to avoid having to login again if that's desirable:

const session = await context.storageState();
// Store them somewhere?
await cache.setCredentials(session, cacheKey);

See browserContext.storageState.

Nico Mee
  • 869
  • 5
  • 6