Use Playwright to automate and test in Microsoft Edge

The Playwright library provides cross-browser automation through a single API.

Playwright is a Node.js library to automate Chromium, Firefox, and WebKit with a single API. Playwright is built to enable cross-browser web automation that is evergreen, capable, reliable, and fast. Because Microsoft Edge is built on the open-source Chromium web platform, Playwright is also able to automate Microsoft Edge.

Playwright launches headless browsers by default. Headless browsers don't display a UI, so instead you must use the command line. You can also configure Playwright to run full (non-headless) Microsoft Edge as well.

Install Playwright and browsers

Note

Playwright requires Node.js version 12 or above. Run node -v from the command line to make sure you have a compatible version of Node.js. The browser binaries for Chromium, Firefox and WebKit work across Windows, macOS, and Linux. For more information, see Playwright System Requirements.

First, install Playwright Test to test your website or app:

npm i -D @playwright/test

To install browsers, run the following command, which downloads Chromium, Firefox, and WebKit:

npx playwright install 

Run a basic test

The approach used by Playwright will be familiar to users of other browser-testing frameworks, such as WebDriver or Puppeteer. You can create an instance of the browser, open a page in the browser, and then manipulate the page by using the Playwright API.

Playwright Test, which is Playwright's test-runner, launches a browser and context for you. An isolated page is then passed into every test, as shown in the following, basic test:

// tests/foo.spec.ts
import { test, expect } from '@playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  const title = page.locator('.navbar__inner .navbar__title');
  await expect(title).toHaveText('Playwright');
});

Now run your tests, as follows:

npx playwright test

For more information about running tests, see Playwright > Getting started.

Run tests in Microsoft Edge

To run your tests in Microsoft Edge, you need to create a config file for Playwright Test, such as playwright.config.ts. Inside the config file, create one project, using Microsoft Edge.

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

const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'Microsoft Edge',
      use: {
        // Supported Microsoft Edge channels are: msedge, msedge-beta, msedge-dev, msedge-canary
        channel: 'msedge',
      },
    },
  ],
};

export default config

If Microsoft Edge isn't already installed on your system, install it through Playwright, as follows:

npx playwright install msedge

When using the above playwright.config.ts file, Playwright Test uses Microsoft Edge to run your tests, as follows:

npx playwright test --headed

Use Playwright as a library

You can also consume Playwright as a library, as shown in the following code. This approach allows you to use a different test-runner.

// example.js
const playwright = require('playwright');

(async () => {
  const browser = await playwright.chromium.launch({
    channel: 'msedge',
  });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://www.microsoft.com/edge');
  await page.screenshot({ path: 'example.png' });

  await browser.close();
})();

The example.png file produced by example.js

example.js is a simple demonstration of the automation and testing scenarios that are enabled by Playwright. To take screenshots in other web browsers, change the above code from await playwright.chromium.launch to the following code:

Firefox:

  const browser = await playwright.firefox.launch({

WebKit:

  const browser = await playwright.webkit.launch({

For more information about Playwright and Playwright Test, go to the Playwright website. Check out the Playwright repo on GitHub. To share your feedback on automating and testing your website or app with Playwright, file an issue.

See also