Testing & Debugging

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

LevelTests WhatSpeedToolsCoverage Goal
UnitSingle function/component logic⚡ Very fastJest, Vitest70–80%
IntegrationMultiple modules working together🔄 MediumRTL, Supertest, MSW15–20%
E2EFull user journeys in real browser🐢 SlowPlaywright, Cypress5–10%

Playwright Locator Strategies

Use higher-priority locators for more resilient tests that survive UI refactors.

#1getByRole('button', { name: 'Submit' })Best — ARIA role + accessible name
#2getByLabel('Email')Great for form inputs with visible label
#3getByText('Welcome back')Good for non-interactive visible text
#4getByTestId('submit-btn')Fallback — requires data-testid attribute
#5locator('button.primary')Last resort — breaks on CSS refactors

Common Pitfalls

Testing every feature with E2E — slow CI, flaky tests, expensive to maintain
E2E should cover critical paths only (signup, checkout, login). Unit/integration tests cover the rest.
Using page.waitForTimeout(2000) — arbitrary sleeps make tests slow and still flaky
Use Playwright's web-first assertions (await expect(locator).toBeVisible()) which auto-retry smartly.
Setting up test data by clicking through the UI in beforeEach — slow, brittle
Seed test data via API calls (Playwright request fixture or cy.request()) — order of magnitude faster.
Running E2E tests against production — pollutes data, requires cleanup, risky
Use a dedicated test/staging environment. Mock third-party APIs (payment, email) in the test environment.

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.