· by Omar Demaría
How to automate your first Playwright test
Step-by-step guide to get started with Playwright in under 30 minutes. Setup, first test and basic CI/CD.
- automation
- playwright
- tutorial
Playwright has become one of the most adopted automation frameworks of the past few years, and for good reason: simple API, real multi-browser support, excellent debugging and great speed. If you've never used it, you'll have your first test running reliably in the next 30 minutes.
Why Playwright
Unlike Selenium, Playwright was built from scratch for modern apps: it handles authentication, networking, downloads and dynamic elements without the workarounds you probably know. And unlike Cypress, it runs in real Chromium, Firefox and WebKit — not in a modified browser version.
For small teams starting QA from scratch, my default recommendation is Playwright.
5-minute setup
mkdir my-qa-suite && cd my-qa-suite
pnpm init
pnpm dlx playwright install
pnpm add -D @playwright/test
The playwright install command downloads the browser versions that Playwright controls — this is what gives you consistent builds locally and in CI.
Your first test
Create tests/login.spec.ts:
import { test, expect } from "@playwright/test";
test("user can log in", async ({ page }) => {
await page.goto("https://myapp.com/login");
await page.getByLabel("Email").fill("[email protected]");
await page.getByLabel("Password").fill("password123");
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page).toHaveURL(/\/dashboard/);
await expect(page.getByText("Welcome")).toBeVisible();
});
The key thing here: we're using role-based selectors (getByLabel, getByRole). These are resilient to markup changes and, by design, accessible — if the test fails, accessibility probably fails too.
Running the test
pnpm playwright test
If it passes: you're done! You have your first automated test. If it fails, run with --debug to open the visual inspector and see exactly where it broke.
Next steps
- Configure GitHub Actions to run tests on every PR
- Add fixtures to reuse setup (login, test data)
- Enable trace viewer for post-mortem debugging in CI
In an upcoming article I'll cover the CI/CD configuration so these tests run automatically on every deploy.