Playwright is a Node library to automate the Chromium, WebKit and Firefox browsers as well as Electron apps with a single API. It enables cross-browser web automation that is ever-green, capable, reliable and fast.

Playwright was built similarly to Puppeteer (opens new window), using its API and so is very different in usage. However, Playwright has cross browser support with better design for test automation.

ADVERTISEMENT

Playwright is a relatively new open-source cross-browser automation framework for end-to-end testing, developed and maintained by Microsoft. It tests across all modern browsers and is designed to be a framework that solves the needs of testing for today’s web apps.

Installation

Playwright has its own test runner for end-to-end tests, we call it Playwright Test.

npm i -D @playwright/test
# install supported browsers
npx playwright install

You can optionally install only selected browsers, see installing browsers for more details. Or you can install no browsers at all and use existing browser channels.

First test

Create tests/foo.spec.js (or tests/foo.spec.ts for TypeScript) to define your test.

ADVERTISEMENT


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');
});