Skip to content

End-to-End Testing

An end-to-end (E2E) test exercises the entire system the way a user does: real browser, real frontend, real backend, real database. Nothing is mocked. It is the highest confidence and the highest cost test you can write — slow, and prone to flakiness.

Because it is expensive, keep the E2E layer thin: cover only the journeys that must never break (signup, login, checkout, payment), not every variation.

Use it for

  • Critical user journeys end to end
  • Wiring across the full stack (browser → API → DB → back)
  • Smoke checks after deployment

Avoid it when

  • The same behaviour can be covered more cheaply by a component or integration test
  • You are tempted to use E2E to test validation rules — that belongs lower
Tool Ecosystem Notes
Playwright Multi Cross-browser, auto-wait, tracing, codegen
Cypress Multi Great DX, time-travel debugging
Selenium Multi The original; WebDriver standard
WebdriverIO Node Flexible WebDriver/DevTools runner
Puppeteer Node Chromium/Firefox control
TestCafe Node No WebDriver, easy setup
Robot Framework + SeleniumLibrary Python Keyword-driven E2E, also RPA
Nightwatch Node WebDriver-based
Terminal window
npm init playwright@latest
npx playwright test
npx playwright test --ui
import { test, expect } from '@playwright/test';
test('user can sign up and reach the dashboard', async ({ page }) => {
await page.goto('/signup');
await page.getByLabel('Email').fill('ada@example.com');
await page.getByLabel('Password').fill('s3cret');
await page.getByRole('button', { name: 'Create account' }).click();
await expect(page.getByRole('heading', { name: 'Dashboard' }))
.toBeVisible();
});
  • Keep the suite small. Cover journeys, not permutations. Push detail down the pyramid.
  • Use resilient locators. Prefer roles and labels over brittle CSS/XPath.
  • Never use fixed sleeps. Use auto-waiting (expect(...).toBeVisible()), not sleep(3).
  • Isolate state. Each test creates its own data so order does not matter.
  • Capture artifacts on failure. Screenshots, video and traces turn a red run into a diagnosable one.
  • Run in parallel in CI and quarantine genuinely flaky tests rather than ignoring red.

Self-assessment quiz

Pick one answer per question, then press Check answers.

  1. What makes an end-to-end test different from other tests?
  2. Why should the E2E layer stay thin?
  3. Which practice should an E2E test avoid?
  4. Which tool offers cross-browser E2E with built-in tracing and codegen?
  5. A critical journey is covered by a fast component test. Do you also need a full E2E test?