Skip to content
SimplyMe
← Back to Playwright course

Chapter 1: Introduction to Playwright

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:

Why Playwright over Selenium or Cypress?

ConcernPlaywrightSeleniumCypress
Cross-browser enginesChromium, Firefox, WebKitChromium, Firefox, WebKit, EdgeChromium-family + Firefox
Auto-waitingBuilt inManual waitsBuilt in
Multiple tabs / windowsYesYesLimited
Network interceptionYesPartialYes
Language bindingsTS/JS, Python, Java, .NETManyJS/TS
ParallelismFirst-class, per-file shardingExternal gridPaid 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:

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.