Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Go to file
2022-03-17 15:28:57 +01:00
.devcontainer chore: fixed devcontainer Docker usage (#3898) 2020-09-17 11:21:10 -07:00
.github devops: delete deprecated 10.14 build trigger (#12825) 2022-03-16 09:07:27 -07:00
browser_patches devops: remove webkit-mac-10.15 from expected builds (#12826) 2022-03-16 10:01:23 -07:00
docs docs: remove ---disable-dev-shm-usage recommendation from docs (#12811) 2022-03-16 15:44:31 -07:00
examples chore: add vue components example (#12797) 2022-03-15 14:47:42 -07:00
installation-tests chore(installation-tests): introduce npm_i to install local packages (#12093) 2022-02-14 14:52:15 -08:00
packages chore: fix markdown links in NPM README's (#12833) 2022-03-17 15:28:57 +01:00
tests chore: restore expect.any()/expect.anything() (#12820) 2022-03-16 21:34:41 +01:00
tests-components chore: add vue components example (#12797) 2022-03-15 14:47:42 -07:00
utils docs: always keep docker references up-to-date in documentation (#12795) 2022-03-16 13:51:39 -07:00
.editorconfig Initial commit 2019-11-19 10:58:15 -08:00
.eslintignore chore: add vue components example (#12797) 2022-03-15 14:47:42 -07:00
.eslintrc.js chore: enable object-curly-spacing in ESLint (#9168) 2021-09-27 18:58:08 +02:00
.gitattributes chore: lang hint for GitHub 2021-12-13 04:05:17 -08:00
.gitignore chore: add ct examples (#12693) 2022-03-11 15:46:11 -08:00
babel.config.json chore: don't include babel compiled files in webpack bundles (#9491) 2021-10-13 19:27:50 -07:00
CODE_OF_CONDUCT.md Revert "chore: rework the crlf in md fix" 2021-01-20 15:45:59 -08:00
CONTRIBUTING.md docs(CONTRIBUTING.md): update how to run a specific test (#11697) 2022-02-01 16:08:08 -08:00
LICENSE chore(license): use Apache 2.0 (#389) 2020-01-06 18:22:35 -08:00
NOTICE chore(license): add NOTICE (#309) 2019-12-19 12:19:54 -08:00
package-lock.json chore: mount should return locator pointing to the component element / fragment (#12718) 2022-03-13 21:26:13 -07:00
package.json chore: add ct examples (#12693) 2022-03-11 15:46:11 -08:00
README.md feat(chromium): roll to r980398 (#12757) 2022-03-14 18:51:46 -07:00
SECURITY.md Revert "chore: rework the crlf in md fix" 2021-01-20 15:45:59 -08:00
tsconfig.json fix(test runner): resolve tsconfig for each file (#11662) 2022-01-26 18:28:42 -08:00

🎭 Playwright

npm version Chromium version Firefox version WebKit version

Documentation | API reference

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.

Linux macOS Windows
Chromium 101.0.4943.0
WebKit 15.4
Firefox 97.0.1

Headless execution is supported for all the browsers on all platforms. Check out system requirements for details.

Looking for Playwright for Python, .NET, or Java?

Installation

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

Using init command

The easiest way to get started with Playwright Test is to run the init command.

# Run from your project's root directory
npm init playwright@latest
# Or create a new project
npm init playwright@latest new-project

This will create a configuration file, optionally add examples, a GitHub Action workflow and a first test example.spec.ts. You can now jump directly to writing assertions section.

Manually

Add dependency and install browsers.

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

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

Capabilities

Resilient • No flaky tests

Auto-wait. Playwright waits for elements to be actionable prior to performing actions. It also has rich set of introspection events. The combination of the two eliminate the need for artificial timeouts - primary cause of flaky tests.

Web-first assertions. Playwright assertions are created specifically for the dynamic web. Checks are automatically retried until the necessary conditions are met.

Tracing. Configure test retry strategy, capture execution trace, videos, screenshots to eliminate flakes.

No trade-offs • No limits

Browsers run web content belonging to different origins in different processes. Playwright is aligned with the modern browsers architecture and runs tests out-of-process. This makes Playwright free of the typical in-process test runner limitations.

Multiple everything. Test scenarios that span multiple tabs, multiple origins and multiple users. Create scenarios with different contexts for different users and run them against your server, all in one test.

Trusted events. Hover elements, interact with dynamic controls, produce trusted events. Playwright uses real browser input pipeline indistinguishable from the real user.

Test frames, pierce Shadow DOM. Playwright selectors pierce shadow DOM and allow entering frames seamlessly.

Full isolation • Fast execution

Browser contexts. Playwright creates a browser context for each test. Browser context is equivalent to a brand new browser profile. This delivers full test isolation with zero overhead. Creating a new browser context only takes a handful of milliseconds.

Log in once. Save the authentication state of the context and reuse it in all the tests. This bypasses repetitive log-in operations in each test, yet delivers full isolation of independent tests.

Powerful Tooling

Codegen. Generate tests by recording your actions. Save them into any language.

Playwright inspector. Inspect page, generate selectors, step through the test execution, see click points, explore execution logs.

Trace Viewer. Capture all the information to investigate the test failure. Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source and many more.

Looking for Playwright for TypeScript, JavaScript, Python, .NET, or Java?

Examples

To learn how to run these Playwright Test examples, check out our getting started docs.

Page screenshot

This code snippet navigates to whatsmyuseragent.org and saves a screenshot.

import { test } from '@playwright/test';

test('Page Screenshot', async ({ page }) => {
    await page.goto('http://whatsmyuseragent.org/');
    await page.screenshot({ path: `example.png` });
});

Mobile and geolocation

This snippet emulates Mobile Safari on a device at a given geolocation, navigates to maps.google.com, performs action and takes a screenshot.

import { test, devices } from '@playwright/test';

test.use({
  ...devices['iPhone 13 Pro'],
  locale: 'en-US',
  geolocation: { longitude: 12.492507, latitude: 41.889938 },
  permissions: ['geolocation'],
})

test('Mobile and geolocation', async ({ page }) => {
  await page.goto('https://maps.google.com');
  await page.locator('text="Your location"').click();
  await page.waitForRequest(/.*preview\/pwa/);
  await page.screenshot({ path: 'colosseum-iphone.png' });
});

Evaluate in browser context

This code snippet navigates to example.com, and executes a script in the page context.

import { test } from '@playwright/test';

test('Evaluate in browser context', async ({ page }) => {
  await page.goto('https://www.example.com/');
  const dimensions = await page.evaluate(() => {
    return {
      width: document.documentElement.clientWidth,
      height: document.documentElement.clientHeight,
      deviceScaleFactor: window.devicePixelRatio
    }
  });
  console.log(dimensions);
});

Intercept network requests

This code snippet sets up request routing for a page to log all network requests.

import { test } from '@playwright/test';

test('Intercept network requests', async ({ page }) => {
  // Log and continue all network requests
  await page.route('**', route => {
    console.log(route.request().url());
    route.continue();
  });
  await page.goto('http://todomvc.com');
});

Resources