Azure AD Based SSO using Playwright

Viewed 608

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 Answers

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.

Related