Skip to content

End-to-End Testing

Drive your whole app like a real user to verify critical journeys work in production.

What you'll learn

  • What end-to-end tests are and the confidence they provide
  • How tools like Playwright and Cypress automate a browser
  • Selecting critical user journeys to cover
  • Fighting flakiness with retries, waits, and isolated state

Concept

Testing From the Outside

An end-to-end (E2E) test interacts with the running application exactly as a user would: it loads a real URL, clicks buttons, types into fields, and reads the resulting page. Because it exercises the entire stack — browser, frontend, API, database — a passing E2E test gives the strongest possible signal that the feature truly works for users.

Tools of the Trade

Playwright and Cypress are the dominant browser automation tools. Playwright (from Microsoft) supports Chromium, Firefox, and WebKit with a single API and runs tests in parallel across browsers. Cypress runs in the browser itself and offers a time-traveling debugger. Both let you write tests in JavaScript or TypeScript and handle the hard parts of browser timing for you.

Choose Critical Journeys

E2E tests are slow and brittle, so you cannot cover every path. Pick the journeys that matter most to the business: sign-up and checkout for an e-commerce site, creating and sharing a document for a collaboration tool. Three to ten well-chosen E2E tests often give more value than a hundred fragile ones. Document what each journey covers so the suite stays intentional.

Beating Flakiness

E2E tests are notorious for failing randomly because of timing. Fight this with auto-waiting (let the tool wait for elements to be ready instead of sleeping), retries for genuinely flaky network conditions, and isolated test data so tests never collide. Run E2E tests on every pull request but keep them out of the tight inner loop — a 30-second E2E suite on every save will kill productivity.

In Practice

When authoring E2E tests, prefer data-testid attributes or accessible roles for selectors so tests survive CSS and copy changes. Create a fresh user account or reset the database at the start of each test so journeys never interfere with one another. If a test fails intermittently, do not reach for retries as a first fix — investigate the race condition, because retrying hides real bugs. Run the E2E suite in a headless browser in CI for speed, but occasionally run it headed locally to watch the automation and catch visual issues the assertions miss. Keep a small library of page-object helpers that wrap common interactions (login, navigate to a record, fill a form) so each journey test reads as a short, high-level script. This keeps the suite maintainable as the application grows.

Example

              // Playwright E2E test for a login journey
import { test, expect } from "@playwright/test";

test("user can log in and see the dashboard", async ({ page }) => {
  await page.goto("https://app.example.com/login");

  await page.fill('[data-testid="email"]', "[email protected]");
  await page.fill('[data-testid="password"]', "correct-horse");
  await page.click('[data-testid="submit"]');

  // Playwright auto-waits for this URL to appear
  await expect(page).toHaveURL(/\/dashboard/);
  await expect(page.locator("h1")).toHaveText("Welcome, Ada");
});
            

The test drives a real browser through the login flow and asserts the user lands on the dashboard. data-testid attributes make selectors resilient to styling changes.

Try it

Common mistakes

The mistake

Using fixed sleeps instead of waiting for conditions

The fix

Use auto-waiting assertions (expect(locator).toBeVisible()) instead of page.waitForTimeout. Fixed sleeps create races on slow machines.

The mistake

Writing E2E tests for every minor UI variation

The fix

Cover the critical journeys once. Push detailed UI checks down to component tests, which are far faster and more stable.

Practice End-to-End Testing

3 exercises

Practice End-to-End Testing

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors