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
Install
npm init playwright@latest in your app's repo.
- 2
Locators
Prefer getByRole, getByLabel and getByText over CSS selectors so tests survive redesigns.
- 3
First test
Open the page, fill the form, click, and expect(page.getByText("Welcome")).toBeVisible().
- 4
Login once
Use a setup project that logs in and saves storageState, reused by other tests.
- 5
Mock APIs
page.route("**/api/products", route => route.fulfill({ json: [] })) to test the empty state.
- 6
Traces
Set trace: "on-first-retry" and open failures with npx playwright show-trace.
- 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