Welcome to the first chapter of the Playwright learning course. By the end of this chapter you will understand what Playwright is, why teams pick it over older browser-automation tools, and how to get a working test running on your machine.
What is Playwright?
Playwright is an open-source framework for end-to-end (E2E) browser automation, maintained by Microsoft. A single API drives Chromium, Firefox, and WebKit, so the same test can validate how a page behaves across all three engines.
Unlike a test runner alone, Playwright ships with everything you usually need:
- A browser driver layer that talks to real browsers via the DevTools protocol.
- Auto-waiting locators that retry until an element is actionable.
- A test runner (
@playwright/test) with assertions, fixtures, parallelism, and reporting. - Tooling such as codegen, trace viewer, and the interactive UI mode.
Why Playwright over Selenium or Cypress?
| Concern | Playwright | Selenium | Cypress |
|---|---|---|---|
| Cross-browser engines | Chromium, Firefox, WebKit | Chromium, Firefox, WebKit, Edge | Chromium-family + Firefox |
| Auto-waiting | Built in | Manual waits | Built in |
| Multiple tabs / windows | Yes | Yes | Limited |
| Network interception | Yes | Partial | Yes |
| Language bindings | TS/JS, Python, Java, .NET | Many | JS/TS |
| Parallelism | First-class, per-file sharding | External grid | Paid dashboard / custom |
The biggest practical win is flakiness reduction. Playwright’s locators wait for
an element to be attached, visible, stable, enabled, and able to receive events
before acting. That removes most of the sleep(2000) calls that plague older suites.
Install Playwright
Node.js 18 or newer is required. Playwright ships as a normal npm package:
# with npm
npm init playwright@latest
# or with pnpm
pnpm create playwright
The scaffolder asks a few questions and then sets up:
playwright.config.ts
tests/
example.spec.ts
To add Playwright to an existing project manually:
pnpm add -D @playwright/test
pnpm exec playwright install --with-deps
The install step downloads the browser binaries. The --with-deps flag also
installs OS-level libraries on Linux, which is what CI images usually need.
Your first test
Create tests/example.spec.ts:
import { test, expect } from "@playwright/test";
test("home page shows the site title", async ({ page }) => {
await page.goto("https://playwright.dev/");
await expect(page).toHaveTitle(/Playwright/);
await expect(page.getByRole("link", { name: "Get started" })).toBeVisible();
});
Run it:
pnpm exec playwright test
Playwright launches a headless browser, navigates, and asserts. To watch it happen, use headed mode:
pnpm exec playwright test --headed
First-run verification
A healthy setup produces output similar to this:
Running 1 test using 1 worker
1 passed (2.4s)
If tests are green, you are ready to write real coverage. Two extra commands are worth knowing early:
pnpm exec playwright test --uiopens UI mode, where you can run individual tests, step through actions, and inspect the DOM at each step.pnpm exec playwright show-reportopens the last HTML report in your browser.
What’s next
In Chapter 2 we look at the anatomy of a spec
file: test(), describe(), expect(), hooks, and how to read failures. Chapter 3
covers the everyday locator and interaction APIs, and Chapter 4 moves into the Page
Object Model, fixtures, network mocking, and CI.