Playwright
Cross-browser end-to-end testing framework with auto-waiting locators, web-first assertions, tracing, and parallel test sharding.
Official Documentation ↗1.64.1. Check the official docs for the latest API surface.Installation
npm install -D @playwright/testpnpm add -D @playwright/testyarn add -D @playwright/testMethods
No methods match this filter.
Playwright drives Chromium, Firefox, and WebKit through a single API. Tests are written against user-visible behavior: roles, labels, and text, rather than CSS selectors. Actions auto-wait, assertions retry, and failed runs can capture traces with a full DOM snapshot per step.
Overview
The runner is provided by @playwright/test, which bundles the test framework, fixtures, assertions, parallel workers, and reporters. Each test gets an isolated browser context, so cookies and storage do not leak between cases. Projects let one suite run against several browsers or device profiles.
Installation
Install @playwright/test as a development dependency, then run npx playwright install –with-deps to fetch browser binaries and system libraries. Scaffold configuration with npm init playwright@latest. Add a baseURL so tests can navigate with relative paths, and a webServer block if the suite should boot the application itself.
Core API walkthrough
test declares a case and injects fixtures. page.getByRole locates elements by accessible role and name, which keeps tests aligned with what assistive technology sees. Web-first assertions such as toBeVisible retry until they pass or time out. page.route intercepts network calls for deterministic fixtures, and defineConfig sets baseURL, projects, retries, and tracing.
Pitfalls
Fixed sleeps hide races instead of fixing them. Sharing state through a single page across tests breaks isolation; rely on the per-test context. Network interception must be registered before navigation. Traces are only written when configured, so enable trace: 'on-first-retry' or retain-on-failure before debugging CI failures. Screenshots taken outside assertions can also mask missing assertions.
Verification
Run npx playwright test locally and open the HTML report with npx playwright show-report. Confirm a deliberately failing assertion fails the run. Use --project=chromium to isolate browser issues, --debug for step-through execution, and the trace viewer to inspect network and DOM state at each action.
FAQ
- Do I need to install browsers separately?
- Yes. The npm package contains the runner only. Run npx playwright install --with-deps to download browser binaries and required system libraries, and repeat it after upgrading Playwright.
- Should tests wait with setTimeout?
- No. Locators auto-wait for actionability and web-first assertions retry until the condition holds. Arbitrary sleeps make suites slow and still flaky; prefer assertions on observable UI state.
- How do I test against my local dev server?
- Set baseURL in playwright.config.ts and either start the server yourself or configure the webServer option so Playwright starts it before tests and waits for the URL to respond.
Report a problem with this API docOpens a pre-filled issue on GitHub.