End-to-End Testing with Playwright
Automate a real browser to test critical journeys such as signup, applying for an opening and payment, across devices.
Intermediate · about 5 hours · difficulty 3/5
Learn first: Testing Fundamentals with Vitest
Playwright drives Chromium, Firefox and WebKit to test your app as a user would: through the real UI, real API and real database.
What to cover
Keep E2E tests for the few journeys that must never break: signup and login, the main create flow (applying to an opening), and anything involving money. Ten solid E2E tests beat a hundred flaky ones.
Writing reliable tests
- Use role and label locators like page.getByRole('button', { name: 'Apply' }).
- Rely on Playwright's auto-waiting and web-first assertions instead of fixed sleeps.
- Log in once and reuse the saved storage state across tests.
- Seed known data before the run and isolate tests from each other.
Tooling
- Codegen records actions to bootstrap a test.
- The trace viewer shows screenshots, network and console for failed runs, which is invaluable in CI.
- Device emulation lets you test the mobile layout.
Pitfalls
- Using waitForTimeout to "fix" flakiness.
- Testing every edge case through the UI instead of at lower levels.
- Running E2E tests against shared environments where other people change data.
You are ready to move on when Playwright tests cover signup, login and applying to an opening on desktop and mobile viewports, and run headless in CI with traces on failure.
Key concepts
- Locators and auto-waiting
- Web-first assertions
- Authentication state reuse
- Test data seeding
- Trace viewer
- Mobile device emulation
- Cypress
Mini project
Write Playwright tests for signup, login, applying to an opening and withdrawing the application, running on desktop Chrome and a mobile viewport with traces captured on failure.
Check yourself
A test passes locally but fails 1 in 10 times in CI. What would you check first, and what tool helps you see what happened?
Free resources
- Playwright: Getting started (Playwright)
- Playwright Best Practices (Playwright)
- Cypress Documentation (Cypress)