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?

1
  • 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. Commented Jul 2, 2021 at 7:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.