← Back to Discord Forum

Testing an app with Azure AD login requirements

mooncake9835posted in #help-playwright
Open in Discord

Hi everyone. Is there anyone from here who have done this before? I want to use e2e testing in our app but our app has a login requirement using microsoft email. This is hard. 😥

This thread is trying to answer question "How can I conduct e2e testing on an app that requires Microsoft email login?"

0 replies


Authenticating Microsoft Email with Playwright

First, set up the authentication process in your test environment. Here's an example of how to perform authentication steps using Playwright. Customize these steps to suit your app.

// playwright.config.ts
import { test, expect } from '@playwright/test';

test('Microsoft email login', async ({ page }) => {
  await page.goto('https://ray.run/login');
  await page.fill('#email', 'your-email@domain.com');
  await page.fill('#password', 'your-password');
  await page.click('#submit');
  await expect(page).toHaveURL('https://ray.run/dashboard');

You can reuse the authenticated state in all your tests. This saves time and ensures full isolation of independent tests. Declare a new setup project in your playwright.config.ts and use it as a dependency for all your testing projects.

// playwright.config.ts
import { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
  projects: [
      name: 'Chrome Stable',
      use: {
        browserName: 'chromium',
        // Run tests in headless mode.
        headless: true,
        // Use the downloaded version of Chrome browser.
        channel: 'chrome',
        // Use the same storage state for all tests.
        storageState: 'path/to/authenticated-state.json',

export default config;

Remember to follow best practices when conducting e2e testing. Use locators to identify elements on the page. Avoid testing third-party dependencies directly. Instead, use Playwright's Network API to guarantee the expected responses. If your app interacts with a database during testing, ensure that you have control over the data being used.

Playwright also offers powerful tooling options such as code generation (codegen) and the Playwright inspector for efficient test creation and debugging. For more tips on writing efficient Playwright test scripts, check out this blog post.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.