Playwright
Overview
Playwright is a framework for web testing and automation that drives Chromium, Firefox, and WebKit through a single API, with bindings for Node.js, Python, Java, and .NET. Its test runner adds auto-waiting locators, web-first assertions, isolated browser contexts, tracing, and parallelism. Read this when writing cross-browser E2E tests, recording tests with codegen, debugging flakiness with traces, or configuring projects/devices.
Official sources
Install / setup
npm init playwright@latest
Source: https://playwright.dev/docs/intro (scaffolds config, examples, and installs browsers; add browsers later with npx playwright install --with-deps).
Core concepts
- Locators —
page.getByRole/getByText/locator() are lazy and auto-retry until actionable.
- Web-first assertions —
expect(locator).toBeVisible() polls until the condition holds or times out.
- Browser contexts — lightweight isolated sessions give each test fresh cookies/storage in parallel.
- Fixtures — the test runner injects
page, context, request, and custom fixtures per test.
- Auto-waiting — actions wait for elements to be visible, stable, and enabled before acting.
- Trace viewer —
--trace on records DOM, network, and actions for post-mortem debugging.
- Codegen —
npx playwright codegen records interactions into runnable test code.
- Projects — config matrix runs the same suite across browsers, devices, and viewports.
Best practices
Common pitfalls
- Manual
waitForTimeout sleeps → rely on auto-waiting locators and expect polling.
- Brittle CSS selectors break on markup changes → use
getByRole/getByTestId.
- Forgetting
await on actions/assertions → every Playwright call returns a promise.
Examples
import { test, expect } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});
Further reading
Related skills
- ../cypress — in-browser E2E alternative with a time-travel debugger
- ../selenium — WebDriver-standard automation across many languages
- ../puppeteer — lower-level Chrome/Firefox control library
1---2name: playwright3description: Playwright is a Microsoft framework for cross-browser web testing and automation across Chromium, Firefox, and WebKit with auto-waiting, tracing, and parallel execution; consult when writing E2E tests, using locators and web-first assertions, generating tests with codegen, or configuring playwright.config.4domain: stack5category: testing6tags: [playwright, e2e, cross-browser, automation, typescript, web-testing, microsoft]7official_sources:8 - https://playwright.dev/docs/intro9 - https://github.com/microsoft/playwright10 - https://www.npmjs.com/package/playwright11verified: 2026-06-1712metadata:13 source: https://skillmd.com/skills/gabriel7silva/playwright14---1516# Playwright1718## Overview19Playwright is a framework for web testing and automation that drives Chromium, Firefox, and WebKit through a single API, with bindings for Node.js, Python, Java, and .NET. Its test runner adds auto-waiting locators, web-first assertions, isolated browser contexts, tracing, and parallelism. Read this when writing cross-browser E2E tests, recording tests with codegen, debugging flakiness with traces, or configuring projects/devices.2021## Official sources22- Docs: https://playwright.dev/docs/intro23- Repo: https://github.com/microsoft/playwright24- Install: https://www.npmjs.com/package/playwright2526## Install / setup27```bash28npm init playwright@latest29```30Source: https://playwright.dev/docs/intro (scaffolds config, examples, and installs browsers; add browsers later with `npx playwright install --with-deps`).3132## Core concepts33- **Locators** — `page.getByRole`/`getByText`/`locator()` are lazy and auto-retry until actionable.34- **Web-first assertions** — `expect(locator).toBeVisible()` polls until the condition holds or times out.35- **Browser contexts** — lightweight isolated sessions give each test fresh cookies/storage in parallel.36- **Fixtures** — the test runner injects `page`, `context`, `request`, and custom fixtures per test.37- **Auto-waiting** — actions wait for elements to be visible, stable, and enabled before acting.38- **Trace viewer** — `--trace on` records DOM, network, and actions for post-mortem debugging.39- **Codegen** — `npx playwright codegen` records interactions into runnable test code.40- **Projects** — config matrix runs the same suite across browsers, devices, and viewports.4142## Best practices43- Prefer role/label/text locators over CSS/XPath for resilient, user-facing tests (https://playwright.dev/docs/locators).44- Use web-first `expect` assertions instead of manual waits (https://playwright.dev/docs/test-assertions).45- Keep tests isolated via contexts; share auth state with `storageState` (https://playwright.dev/docs/auth).46- Enable traces/retries in CI to triage flakes (https://playwright.dev/docs/test-retries).4748## Common pitfalls49- Manual `waitForTimeout` sleeps → rely on auto-waiting locators and `expect` polling.50- Brittle CSS selectors break on markup changes → use `getByRole`/`getByTestId`.51- Forgetting `await` on actions/assertions → every Playwright call returns a promise.5253## Examples54```ts55import { test, expect } from '@playwright/test';5657test('has title', async ({ page }) => {58 await page.goto('https://playwright.dev/');59 await expect(page).toHaveTitle(/Playwright/);60});61```6263## Further reading64- https://playwright.dev/docs/test-configuration — `playwright.config` and projects65- https://playwright.dev/docs/trace-viewer — debugging with traces6667## Related skills68- ../cypress — in-browser E2E alternative with a time-travel debugger69- ../selenium — WebDriver-standard automation across many languages70- ../puppeteer — lower-level Chrome/Firefox control library