Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 35 ยท Getting Started

What End-to-End Testing Is

Learn what an end-to-end browser test does, how it differs from unit tests, how a test drives a page, and where Cypress and Playwright fit in.

An end-to-end test (usually shortened to e2e test) opens your application in a real browser and uses it the way a person would: it loads a page, types into fields, clicks buttons and then checks what appeared on the screen. Nothing is replaced by a fake. The browser, the JavaScript, the network, the server and often the database all take part.

That is the whole appeal. A unit test can tell you that a function validates an email address correctly. Only an end-to-end test can tell you that the sign-in button on the real page is wired to that function, that the request reaches the server, and that the welcome message shows up. This tutorial teaches the two most popular tools for writing such tests, Cypress and Playwright, and the habits that keep a browser test suite fast and trustworthy.

The real tools need Node.js, a browser and a running copy of your app, so they cannot run on this site. Every lesson shows the real commands and code in read-only blocks, and then gives you runnable stand-ins: small programs that reproduce how the idea works inside. Each lesson tells you plainly which part is real and which is the stand-in.

What a browser test actually does

Every end-to-end test follows the same four steps, whichever tool you use:

  1. Arrange. Put the app in a known starting state: open a URL, maybe log in, maybe create some data.
  2. Find. Locate the element you want on the page (a button, an input, a heading).
  3. Act. Do something to it the way a user would: click, type, select, press a key.
  4. Assert. Check that the page now shows what you expect.

Here is one complete test in each tool. Do not worry about the details yet; the next lessons explain every command.

JavaScript
// Cypress (read-only)
describe('sign in', () => {
  it('welcomes the user', () => {
    cy.visit('/login')
    cy.get('[data-cy=email]').type('[email protected]')
    cy.contains('button', 'Sign in').click()
    cy.contains('Signed in as [email protected]').should('be.visible')
  })
})
TypeScript
// Playwright (read-only)
import { test, expect } from '@playwright/test';

test('welcomes the user', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('[email protected]');
  await page.getByRole('button', { name: 'Sign in' }).click();
  await expect(page.getByText('Signed in as [email protected]')).toBeVisible();
});

The two tests read almost like instructions to a very patient assistant: go to the login page, type an email, press the button, expect a message. Notice that neither test mentions a function, a component or a variable inside your app. They only describe what is visible. That is what "user-level" means.

Unit tests and end-to-end tests compare

Tests come in layers, and each layer answers a different question.

Unit test Component test End-to-end test
What runs One function or class One component in a simulated page The whole app in a real browser
Speed Milliseconds Tens of milliseconds Seconds
Fails when The logic is wrong The component misbehaves Any part of the system breaks
Typical cost to debug Low Low to medium Medium to high
Confidence it gives "This piece works" "This piece works on screen" "A user can really do this"

None of these layers replaces the others. See Testing in JavaScript and Testing React Components for the lower layers, and the next lesson, Testing Strategy and the Test Pyramid, for how to split your effort between them.

flowchart LR
  T["Test script"] -->|"commands"| B["Real browser"]
  B -->|"HTTP requests"| S["Your server"]
  S --> D[("Database")]
  B -->|"page state"| T

An end-to-end test drives a real browser, which talks to the real server and database; the test then reads the page state back.

How a test drives a page

A browser page is a tree of elements (the DOM). Your test script is just a program that keeps asking that tree two kinds of questions:

  • Queries: "Is there a button whose text is Sign in?" The answer is an element, or nothing.
  • Commands: "Click that element." The browser then fires the same events a real click would.

After every command, the page may change: handlers run, requests fly, new elements appear. The assertion at the end checks the tree again.

The stand-in below builds a tiny fake page (a tree of plain objects), a miniature "browser" that can find, type and click, and one end-to-end style test. It is not Cypress or Playwright, but it has the same shape: find an element, act on it, assert on what you read back.

JS A fake page driven by a tiny test driver

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The first two tests pass and the third fails with a message naming the missing element. That is exactly how real tools behave when a selector matches nothing, except that Cypress and Playwright also wait for the element to show up before giving up. You will build that waiting behavior in the stand-ins of Your First Cypress Test and Your First Playwright Test.

What only an end-to-end test can catch

Unit tests check pieces in isolation, so they cannot see mistakes in the connections between pieces. The next stand-in builds the same sign-in page twice. In the second copy a developer forgot to read the input field in the click handler. A unit test of the validation function still passes, because the function itself is fine. The user-level test fails.

JS The bug a unit test cannot see

Press Run (or Ctrl + Enter) to see the console output here.

No output.

In the real world the "connection" that breaks might be a renamed form field, a request sent to the wrong URL, a CSS rule that hides the button, or a script that fails to load. A browser test catches all of these because it uses the finished product.

The price of that confidence

Browser tests are valuable but not free:

  • They are slower. A page load, a render and a network round trip take real time. A good unit test runs in a millisecond; a good e2e test takes a few seconds.
  • They are broader. When one fails, the cause could be the test, the front end, the back end, the data or the environment.
  • They can be flaky. If a test sometimes passes and sometimes fails with no code change, people stop trusting it. Finding and Fixing Flaky Tests is dedicated to this problem.

So you write fewer of them and aim them at the journeys that matter most: signing up, logging in, searching, paying. The rest of this tutorial shows how to write each one cleanly and keep it stable.

Where Cypress and Playwright fit

Both tools give you three things: a way to launch and control a browser, an API for finding elements and acting on them, and a test runner that reports passes, failures and evidence such as screenshots. They differ in how they are built. The comparison lesson, Cypress vs Playwright, explains it in depth. For now, remember the shared ideas: tests are written in JavaScript or TypeScript, elements are found with selectors or locators, and assertions retry until they pass or time out, which is what makes modern browser tests reliable.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main difference between a unit test and an end-to-end test?

    Unit tests isolate a small piece of logic. End-to-end tests run the full system the way a user would, including the browser, network and server.
  2. 2. Which sequence describes the steps of a typical browser test?

    Arrange, find, act, assert is the shape of nearly every end-to-end test, in both Cypress and Playwright.
  3. 3. A form field was renamed, so the click handler reads the wrong value. The unit test of the validation function still passes. Which test catches the bug?

    The mistake is in how pieces are connected. Only a test that goes through the real page exercises those connections.
  4. 4. Why do teams write fewer end-to-end tests than unit tests?

    End-to-end tests cost more to run and maintain, so you point them at the most important user journeys.

Summary

  • An end-to-end test drives your real app in a real browser and checks what a user would see.
  • Every test follows arrange, find, act, assert.
  • E2e tests catch wiring and integration bugs that unit and component tests cannot.
  • They are slower and more fragile than lower-level tests, so use them for the journeys that matter most.
  • Cypress and Playwright both provide a browser controller, an element API and a test runner, with retrying assertions at the core.
  • On this site the real tools are read-only; the stand-ins show how they work inside.

Next: Testing Strategy and the Test Pyramid