Install
Playwright · Reference cheat sheet
Install
Playwright · Reference cheat sheet
📋 Overview
Playwright is a cross-browser E2E library for Chromium, Firefox, and WebKit. Install the Node package, then download browser binaries with npx playwright install.
🔧 Core concepts
| Piece | Role |
|---|---|
@playwright/test | Test runner + assertions |
playwright | Library-only (no runner) |
| Browser binaries | Chromium / Firefox / WebKit |
| System deps | OS libs for headed/headless |
Install (npm):
npm init playwright@latest
# or into existing project:
npm i -D @playwright/test
npx playwright install
npx playwright install --with-deps # CI / LinuxPython / Java / .NET also exist; this folder focuses on the JS/TS runner.
💡 Examples
Minimal package scripts:
{
"scripts": {
"test": "playwright test",
"test:ui": "playwright test --ui",
"test:headed": "playwright test --headed",
"report": "playwright show-report"
}
}Verify browsers:
npx playwright --version
npx playwright install chromium
npx playwright install firefox webkitFirst test (tests/example.spec.ts):
import { test, expect } from '@playwright/test';
test('homepage has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
await expect(page).toHaveTitle(/Playwright/);
});Run:
npx playwright test
npx playwright test --project=chromium
npx playwright test tests/example.spec.ts⚠️ Pitfalls
- Installing the npm package without
playwright install→ missing browser binaries. - Mixing global and local CLI — prefer
npx playwrightfrom the project. - Skipping
--with-depson Linux CI causes cryptic launch failures. - Pinning
@playwright/testwithout reinstalling browsers after upgrades. - Using
playwrightalone when you need@playwright/testfixtures.