# End-to-End Testing with Playwright

> Automate real browsers to test critical user journeys; Playwright recommended, Cypress as the common alternative. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/frontend/e2e-testing
Last updated: 2026-11-28

Automate real browsers to test critical user journeys; Playwright recommended, Cypress as the common alternative.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [Component Testing with Testing Library](https://www.internhack.in/roadmaps/tracks/frontend/component-testing)

End-to-end (E2E) tests drive a real browser against your running app, covering routing, network, storage and third-party scripts together. They catch the bugs that slip between units, but they are slower and more brittle, so reserve them for **critical journeys**: sign up, log in, search, checkout, and anything that would page someone at 3 a.m.

### Playwright (recommended)

- Runs Chromium, Firefox and WebKit, in parallel, headless in CI.
- **Locators** mirror Testing Library: `page.getByRole("button", { name: "Pay" })`.
- **Auto-waiting** and web-first assertions (`await expect(locator).toBeVisible()`) remove most sleeps and flakiness.
- **Codegen** records interactions into test code; the **trace viewer** shows screenshots, DOM snapshots and network for each step of a failed run.
- Network interception, multiple tabs and contexts, mobile emulation and saved auth state.

### Cypress (alternative)

Runs inside the browser with an excellent interactive runner and time-travel debugging. Widely used in existing projects. Historically more limited with multiple tabs and cross-origin flows.

### Writing stable E2E tests

- Seed or create test data through APIs, not by clicking through setup screens.
- Log in once and reuse storage state.
- Never use fixed timeouts; wait for observable conditions.
- Keep tests independent so they can run in parallel.
- Run them in CI against a preview deployment and keep traces on failure.

### Good enough to move on

You can write three reliable Playwright tests for your app's critical paths, run them headless in CI across two browsers and debug a failure with the trace viewer.

## Key concepts

- **When E2E tests are worth it**
- **Playwright**
- **Cypress**
- **Locators and web-first assertions**
- **Auth state and test data setup**
- **Trace viewer and debugging**
- **Running E2E in CI**
- **Visual regression screenshots**

## Mini project

Add Playwright to your project with tests for signup, search and add-to-cart-then-checkout, reuse login state across tests, and run them in GitHub Actions with traces uploaded on failure.

## Check yourself

Why is \`await page.waitForTimeout(3000)\` a bad way to wait for search results, and what should you use instead?

## Free resources

- [Playwright Introduction](https://playwright.dev/docs/intro) (Playwright)
- [Playwright Best Practices](https://playwright.dev/docs/best-practices) (Playwright)
- [Cypress Documentation](https://docs.cypress.io/) (Cypress)

Previous: [Component Testing with Testing Library](https://www.internhack.in/roadmaps/tracks/frontend/component-testing) · Next: [WCAG and Inclusive Design Principles](https://www.internhack.in/roadmaps/tracks/frontend/wcag)

## More in Testing Frontend Applications

- [Testing Fundamentals with Vitest](https://www.internhack.in/roadmaps/tracks/frontend/testing-fundamentals)
- [Component Testing with Testing Library](https://www.internhack.in/roadmaps/tracks/frontend/component-testing)
- [End-to-End Testing with Playwright](https://www.internhack.in/roadmaps/tracks/frontend/e2e-testing)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Frontend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/frontend)
