What are the steps to use Playwright for e2e testing of an application that requires Microsoft email authentication?


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.


Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

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.