Skip to content

Playwright Cheatsheet

Browser automation and testing framework by Microsoft.

01

Getting Started

Basic Test

Playwright tests use fixtures like { page }.

playwright
import { test, expect } from "@playwright/test";

test("home", async ({ page }) => {
  await page.goto("/");
  await expect(page).toHaveTitle("Welcome");
});

Interactions

Common interaction methods.

playwright
await page.fill("input", "hello");
await page.click("button");
await page.waitForSelector(".result");

Locators

Locator API for resilient element selection.

playwright
const button = page.getByRole("button", { name: "Submit" });
await button.click();

const item = page.getByText("Hello");
await expect(item).toBeVisible();
02

Features

Multi-Browser

Cross-browser testing out of the box.

playwright
test.describe.configure({ mode: "serial" });
test("works in all", async ({ page, browserName }) => {
  // runs in chromium, firefox, webkit
});

Screenshot

Visual regression testing.

playwright
await page.screenshot({ path: "screenshot.png" });
await expect(page).toHaveScreenshot();

Was this helpful?