Playwright
End-to-end testing framework by Microsoft that supports Chromium, Firefox, and WebKit. Auto-waiting, parallel execution, the Trace Viewer for debugging, a codegen recorder, and built-in API testing — all in one modern testing toolkit.
What is Playwright?
Playwright is an open-source end-to-end testing framework developed by Microsoft. It automates real browser instances — Chromium (Chrome/Edge), Firefox, and WebKit (Safari) — via a single, consistent API. Unlike older automation tools, Playwright was designed from the ground up for modern web applications: single-page apps, server-rendered apps, multi-tab flows, iframes, and web components.
Tests run in parallel by default, use smart auto-waiting to eliminate flakiness, and can target mobile device emulation. The Trace Viewer records a full timeline of every test action for deterministic debugging. Codegen records user interactions and produces test code automatically. Playwright supports TypeScript, JavaScript, Python, Java, and C#.
Key Features
- Auto-waiting — waits for elements to be visible, enabled, and stable before acting — no explicit waits needed
- Cross-browser — Chromium, Firefox, and WebKit with a single test suite; mobile device emulation included
- Trace Viewer — captures screenshots, DOM snapshots, and network activity for every test step; replay in the browser
- Codegen — record interactions in a real browser and generate test code using accessible locators
- Fixtures — composable, reusable test setup (auth state, mock services, custom page objects) via test.extend()
- API testing — built-in HTTP client for testing REST APIs without a browser in the same test suite
- Parallelism — tests run in parallel by default; workers and sharding configurable for large CI suites
- Component testing — test React, Vue, and Svelte components in isolation with @playwright/experimental-ct-*
Installation
# Create a new project with Playwright pre-configured npm init playwright@latest # Add Playwright to an existing project npm install --save-dev @playwright/test # Install browser binaries (Chromium, Firefox, WebKit) npx playwright install # Run tests npx playwright test # Run tests with UI mode (interactive, time-travel debugging) npx playwright test --ui # Generate tests using the codegen tool npx playwright codegen https://example.com
Writing Tests
Tests are organized with test.describe blocks and individual test() cases. Use accessible locators (getByRole, getByLabel) rather than CSS selectors for resilient tests.
// tests/auth.spec.ts
import { test, expect } from '@playwright/test';
test.describe('Authentication', () => {
test('user can log in with valid credentials', async ({ page }) => {
await page.goto('/login');
// Fill in the login form
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('s3cret');
await page.getByRole('button', { name: 'Sign in' }).click();
// Playwright auto-waits for navigation to complete
await expect(page).toHaveURL('/dashboard');
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
});
test('shows error for wrong password', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('wrong');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByText('Invalid credentials')).toBeVisible();
});
}); Fixtures for Reusable Setup
Fixtures replace beforeEach hooks with composable, type-safe setup. An auth fixture logs in once and passes the authenticated page to each test that needs it — without repeating the login steps.
// fixtures/auth.ts — a custom fixture that pre-authenticates
import { test as base, expect } from '@playwright/test';
type AuthFixtures = {
authenticatedPage: Page;
};
export const test = base.extend({
authenticatedPage: async ({ page }, use) => {
// Log in once, share the authenticated browser state
await page.goto('/login');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('adminpass');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.waitForURL('/dashboard');
await use(page);
},
});
// Use in tests
test('admin can delete a user', async ({ authenticatedPage }) => {
await authenticatedPage.goto('/users');
// ...
}); API Testing
The request fixture gives you a full HTTP client for testing APIs without launching a browser. Useful for testing REST endpoints or verifying back-end state after a UI action.
// API testing with Playwright — no browser needed
import { test, expect } from '@playwright/test';
test('GET /api/users returns a list', async ({ request }) => {
const response = await request.get('/api/users');
expect(response.status()).toBe(200);
const users = await response.json();
expect(Array.isArray(users)).toBe(true);
expect(users.length).toBeGreaterThan(0);
expect(users[0]).toHaveProperty('id');
});
test('POST /api/users creates a new user', async ({ request }) => {
const response = await request.post('/api/users', {
data: { name: 'Alice', email: '[email protected]' }
});
expect(response.status()).toBe(201);
const user = await response.json();
expect(user.email).toBe('[email protected]');
}); Configuration
playwright.config.ts controls browsers, parallelism, retries, base URL, tracing, and screenshot policies. Define multiple projects to test across browsers and viewports in one run.
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true, // run tests in parallel
forbidOnly: !!process.env.CI, // fail CI if test.only is left in
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry', // capture traces on retry
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
{ name: 'Mobile Chrome', use: { ...devices['Pixel 5'] } },
],
}); Playwright vs Cypress
| Feature | Playwright | Cypress |
|---|---|---|
| Browser support | Chrome, Firefox, WebKit | Chrome-based (FF/WebKit experimental) |
| Multi-tab / multi-origin | Yes | Limited |
| Test languages | TS, JS, Python, Java, C# | JS / TS only |
| Interactive debugger | UI mode / Trace Viewer | Built-in Test Runner GUI |
| Component testing | Experimental | Stable |
| Parallelism (free) | Yes (built-in) | Requires Cypress Cloud |
Pros and Cons
Pros
- ✓ True cross-browser: Chrome, Firefox, and WebKit in one suite
- ✓ Auto-waiting eliminates most flaky test issues
- ✓ Trace Viewer makes post-mortem debugging straightforward
- ✓ Multi-language support (Python, Java, C# in addition to TS/JS)
- ✓ Free parallelism without a cloud service
Cons
- ✗ Component testing is still experimental
- ✗ Interactive test runner less polished than Cypress GUI
- ✗ Steeper initial learning curve compared to Cypress
- ✗ No built-in cloud recording dashboard (third-party integrations exist)
- ✗ Browser binaries (~300 MB) add to CI download time
Frequently Asked Questions
What is Playwright?▼
Playwright is an end-to-end testing framework developed by Microsoft. It automates Chromium, Firefox, and WebKit browsers using a single API, supports auto-waiting, parallel execution, the Trace Viewer for debugging, a codegen tool for recording tests, and built-in API testing. Tests are written in TypeScript, JavaScript, Python, Java, or C#.
How does Playwright's auto-waiting work?▼
Playwright automatically waits for elements to be actionable before interacting with them. When you call page.click() or page.fill(), Playwright waits for the element to be visible, enabled, and stable (not animating) before acting. This eliminates most explicit waits and sleeps that make tests fragile. You can configure a global timeout and per-action timeouts in the config.
What is the Playwright Trace Viewer?▼
The Trace Viewer is a debugging tool that records a full trace of a test run — every action, network request, console log, and DOM snapshot — and lets you replay it in a browser-based timeline. Enable it with trace: 'on-first-retry' in the config (so it only runs on failing retries, keeping storage low). View traces with npx playwright show-report or by uploading to the Playwright CI portal.
How does Playwright codegen work?▼
Running npx playwright codegen <URL> opens a browser with an inspector overlay. As you interact with the page — clicking, typing, navigating — Playwright records each action and generates test code in real time. The generated code uses recommended locator strategies (getByRole, getByLabel, getByText) rather than fragile CSS selectors. It is a useful starting point but generated tests typically need refinement.
Can Playwright test APIs without a browser?▼
Yes. Playwright includes a built-in APIRequestContext (accessed via the request fixture in tests) that lets you make HTTP requests and assert on responses — no browser required. This is useful for testing REST API endpoints, verifying backend state after a UI action, or running mixed browser + API test scenarios in the same test file.
How does Playwright compare to Cypress?▼
Playwright runs tests out-of-process (a separate Node process controlling the browser) while Cypress runs inside the browser. Playwright natively supports Chromium, Firefox, and WebKit; Cypress primarily targets Chrome-based browsers (Firefox and WebKit support is experimental). Playwright has better multi-tab, iframe, and multi-origin support. Cypress has a more polished interactive dashboard and an established cloud recording service. Both are excellent choices for modern E2E testing.
Related Products
on GumroadGitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad →Premium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad →DevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →You Might Also Need
SQL to TypeScript Types
Convert SQL CREATE TABLE statements to TypeScript interfaces and Zod schemas. Maps SQL column types to TypeScript with nullability.
Open free tool →
TypeScript Discriminated Union Builder
Build TypeScript discriminated unions visually. Add variants with fields and get type-safe switch statements, type guards, and exhaustive checking code.
Open free tool →
TypeScript Playground
Write TypeScript and instantly see compiled JavaScript output. Strip interfaces, types, generics, enums, and decorators. Share code via URL. No install needed.
Open free tool →
More Free Tools
Related Articles
Playwright E2E Testing Guide 2026: Complete Setup & Best Practices
A complete guide to Playwright end-to-end testing in 2026. Covers installation, Page Object Model, visual regression, parallel execution, GitHub Actions CI, and debugging techniques with TypeScript examples.
DevOps Automation Tools in 2026: Orchestrating the Software Delivery Pipeline
Master DevOps automation with this guide to the tools that orchestrate modern software delivery. Covers CI/CD pipelines, infrastructure provisioning, configuration management, testing automation, and the emerging AI-assisted automation patterns that define 2026.
End-to-End Testing in 2026: Writing Tests That Don't Lie
E2E testing guide 2026: choose Playwright or Cypress, eliminate flakiness, structure test suites for CI/CD, and understand real application quality limits.
Playwright vs Selenium 2026: Which Should You Choose?
Complete comparison of Playwright and Selenium for browser automation and end-to-end testing in 2026. Performance benchmarks, API differences, migration guide, and when to use each.
QA Automation in 2026: From Script Kiddies to Intelligent Test Suites
How modern QA automation has evolved in 2026 — AI-driven test generation, self-healing frameworks, shift-left strategies, and the real cost of not automating. A practical guide for teams still writing tests manually.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →