End-to-End Testing
E2E tests simulate real user journeys in a real browser — clicking, typing, navigating. Playwright and Cypress give you cross-browser automation with smart auto-waiting, network interception, and powerful debugging tools.
What is end-to-end testing?
End-to-end (E2E) tests drive a real browser through your running app the way a user would: open pages, fill forms, click buttons and check the results. Playwright and Cypress are the main tools. E2E tests catch problems that only appear when everything is connected, but they're slower, so cover your most important user journeys.
import { test, expect } from "@playwright/test";
test("user can sign up", async ({ page }) => {
await page.goto("/signup");
await page.getByLabel("Email").fill("ada@example.com");
await page.getByRole("button", { name: "Create account" }).click();
await expect(page.getByText("Welcome")).toBeVisible();
});Testing Levels Recap
| Level | Tests What | Speed | Tools | Coverage Goal |
|---|---|---|---|---|
| Unit | Single function/component logic | ⚡ Very fast | Jest, Vitest | 70–80% |
| Integration | Multiple modules working together | 🔄 Medium | RTL, Supertest, MSW | 15–20% |
| E2E | Full user journeys in real browser | 🐢 Slow | Playwright, Cypress | 5–10% |
Playwright Locator Strategies
Use higher-priority locators for more resilient tests that survive UI refactors.
getByRole('button', { name: 'Submit' })Best — ARIA role + accessible namegetByLabel('Email')Great for form inputs with visible labelgetByText('Welcome back')Good for non-interactive visible textgetByTestId('submit-btn')Fallback — requires data-testid attributelocator('button.primary')Last resort — breaks on CSS refactorsCommon Pitfalls
Interactive Demo
Code Editor
<p>End-to-end tests run a real browser against your app, so they run in your terminal, not here.</p>
<pre>// tests/signup.spec.ts (Playwright)
import {
test,
expect,
} from "@playwright/test";
test("a visitor can sign up", async ({ page }) => {
await page.goto("http://localhost:3000/signup");
await page.getByLabel("Email").fill("ada@example.com");
await page.getByLabel("Password").fill("correct-horse-42");
await page.getByRole("button", { name: "Create account" }).click();
await expect(page.getByText("Welcome, Ada")).toBeVisible();
});
// run: npx playwright test (add --ui for the visual runner)</pre>Preview
End-to-End Testing: summary
Key points
- Playwright waits for elements automatically; avoid fixed
sleeps. - Run E2E tests against a production-like build in CI.
- Reset test data between runs so tests don't depend on each other.
Frequently asked questions
›Playwright or Cypress?
Playwright supports Chromium, Firefox and WebKit, runs tests in parallel, and is very fast. Cypress has an excellent interactive runner. Both are solid choices.