🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

End-to-end tests with Playwright

Reliable end-to-end tests for one of your own web apps, across Chromium, Firefox and WebKit.

Intermediate⏱ 8–12 hoursđŸĒœ 7 stepsTypeScriptPlaywright

What you'll learn

  • ◆Auto-waiting and resilient locators
  • ◆Fixtures and test isolation
  • ◆Traces for debugging failures

What you'll build

  • ✓Tests for sign-up, login and a core flow
  • ✓Runs on three browsers
  • ✓Mocked network for edge cases
  • ✓Trace viewer on failure

Step-by-step guide

  1. 1

    Install

    npm init playwright@latest in your app's repo.

  2. 2

    Locators

    Prefer getByRole, getByLabel and getByText over CSS selectors so tests survive redesigns.

  3. 3

    First test

    Open the page, fill the form, click, and expect(page.getByText("Welcome")).toBeVisible().

  4. 4

    Login once

    Use a setup project that logs in and saves storageState, reused by other tests.

  5. 5

    Mock APIs

    page.route("**/api/products", route => route.fulfill({ json: [] })) to test the empty state.

  6. 6

    Traces

    Set trace: "on-first-retry" and open failures with npx playwright show-trace.

  7. 7

    CI

    Use the generated GitHub Actions workflow; upload the HTML report as an artifact.

🚀 Make it stand out

  • +Visual comparisons (toHaveScreenshot)
  • +Accessibility checks with axe
  • +Run against preview deployments