Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal

Two Playwright journeys for a React task board in real Chromium: the webServer block that starts the app, auto-waiting in the call log, a first draft that times out on '6 of 6 shown', and the page snapshot and trace that show the test was wrong, not the app.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

What you will learn

  • Explain what an end-to-end test runs: test runner, real browser and the app
  • Let Playwright start the dev server with the webServer block
  • Write a journey with getByRole, fill, click and web-first expect assertions
  • Read a timeout failure, the page snapshot and the trace to find the real cause

Before you start

  • React component tests with Vitest and Testing Library
  • Running a Vite app with npm run dev

Before opening night, a theatre runs a full dress rehearsal: real stage, real costumes, the whole play from the first scene to the last. An end-to-end test is that rehearsal for your app. It opens a real browser, uses the page like a person, and checks what the page says at the end.

This article runs two Playwright journeys against the task board from the component tests article. Every log line, error and timing comes from the project's own test runs.

Three things run together

Playwright, Chromium and the app Playwright reads the test, sends commands Chromium clicks and types, no window needed The app task board at localhost:5173 "click add" goes right, the page's answer comes back
Nothing is pretend: a real browser, a real page and a real server running the app.

Playwright starts the app for you

import { defineConfig, devices } from '@playwright/test'

export default defineConfig({
  testDir: './e2e',
  reporter: 'list',
  expect: { timeout: 3_000 },
  use: {
    baseURL: 'http://localhost:5173',
    trace: 'retain-on-failure',
  },
  projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
  // start the app before the tests, stop it after
  webServer: {
    command: 'npm run dev',
    url: 'http://localhost:5173',
    reuseExistingServer: true,
  },
})

The webServer block runs npm run dev, keeps knocking on the url until the app answers, and only then starts the tests. reuseExistingServer: true means: if the app is already running, use that one. A few other lines matter later: baseURL so tests can write page.goto('/'), a 3-second expect timeout, and trace: 'retain-on-failure', which keeps a trace for every failed test. The project runs it with "e2e": "playwright test".

The test is a script for the browser

import { expect, test } from '@playwright/test'

test('the done filter lists only finished tasks', async ({ page }) => {
  await page.goto('/')
  await expect(page.getByText('5 of 5 shown')).toBeVisible()
  await page.getByRole('button', { name: 'done' }).click()
  await expect(page.getByText('2 of 5 shown')).toBeVisible()
  await expect(page.getByText('Write report')).toBeVisible()
  await expect(page.getByText('Email Jack')).toBeHidden()
})

test('a new task joins the open list', async ({ page }) => {
  await page.goto('/')
  await page.getByRole('button', { name: 'open' }).click()
  await page.getByRole('textbox', { name: 'New task' }).fill('Pay rent')
  await page.getByRole('button', { name: 'add' }).click()
  await expect(page.getByText('4 of 6 shown')).toBeVisible()
  await expect(page.getByText('Pay rent')).toBeVisible()
})

The second test is the journey: open the page, click open, fill the box named New task with "Pay rent", click add, then check. Everything is found by role and name, the way a person would describe it. With the open filter on and six tasks in total, the page should say "4 of 6 shown".

Playwright waits until the page is ready

Here is Playwright's own call log for the click on open:

waiting for getByRole('button', { name: 'open' })
  locator resolved to <button class="" aria-pressed="false">open</button>
attempting click action
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  performing click action
  click action done
  waiting for scheduled navigations to finish
  navigations have finished

It finds the button, waits until it is visible, enabled and stable, clicks, then waits for the page to settle. A button that's still moving or still disabled doesn't get clicked. That is why the test has no sleep or manual waits, and why expect(...).toBeVisible() keeps retrying until its timeout.

One flow passes, one fails

The first draft of the second test expected "6 of 6 shown". Running npx playwright test:

Running 2 tests using 1 worker

  ok 1 [chromium] › e2e\board.spec.ts:3:1 › the done filter lists only finished tasks (548ms)
  x  2 [chromium] › e2e\board.spec.ts:12:1 › a new task joins the open list (3.6s)

    Error: expect(locator).toBeVisible() failed

    Locator: getByText('6 of 6 shown')
    Expected: visible
    Timeout: 3000ms
    Error: element(s) not found

    > 17 |   await expect(page.getByText('6 of 6 shown')).toBeVisible()

  1 failed
  1 passed (9.1s)

(Shortened; the full output also prints the call log, the code around line 17 and the trace path.) The 3.6 seconds is a clue: almost all of it was waiting. Playwright looked for "6 of 6 shown" for 3000 ms and never found it. The error says what was missing, but not why.

The trace shows the page at that moment

Because of retain-on-failure, the run kept a trace, and the output prints the command to open it (npx playwright show-trace with the trace.zip path). The trace lists every action with its time:

   248.5 ms  Navigate to "/"
    79.8 ms  Click getByRole('button', { name: 'open' })
    28.1 ms  Fill "Pay rent" getByRole('textbox', { name: 'New task' })
    63.6 ms  Click getByRole('button', { name: 'add' })
  3019.4 ms  FAILED Expect "toBeVisible"

Next to the actions it shows the page as it looked at that moment. The failing run also wrote a page snapshot (trimmed to the relevant lines):

- button "open" [pressed] [ref=e6] [cursor=pointer]
- paragraph [ref=e9]: 4 of 6 shown
- list [ref=e10]:
  - listitem [ref=e11]: â—‹ Email Jack
  - listitem [ref=e12]: â—‹ Plan sprint
  - listitem [ref=e13]: â—‹ Call Olivia
  - listitem [ref=e14]: â—‹ Pay rent

The open button is pressed and the page says 4 of 6 shown. The filter was still on, so of course it never said 6 of 6. The test was wrong, not the app. Fix the expectation to "4 of 6 shown":

Running 2 tests using 1 worker

  ok 1 [chromium] › e2e\board.spec.ts:3:1 › the done filter lists only finished tasks (539ms)
  ok 2 [chromium] › e2e\board.spec.ts:12:1 › a new task joins the open list (497ms)

  2 passed (5.5s)

It failed first and passed after, so we can trust it.

Keep the journeys few

Few journeys, many small tests E2E component tests many small checks, one function at a time a few journeys in a real browser
Every journey costs time. Here two journeys took 5.5 seconds in total.

Keep end-to-end tests for the paths that matter, and cover the rest with fast component and unit tests.

Recap

IdeaWhat to remember
What runsPlaywright, a real Chromium and the app itself
webServerStarts npm run dev before the tests and waits for the URL
LocatorsgetByRole with a name, getByText
WaitingActions wait for visible, enabled and stable; expect retries until its timeout
FailuresRead the error, then the page snapshot and the trace
How manyA few journeys that matter

Try it yourself: add a third journey that adds a task with the done filter on and checks it does not appear in the list. Run it, watch it fail once on purpose, then make it pass.

Keep going in React · 19 of 59

Previous
React Component Tests With Vitest and Testing Library: Test What the User Sees
Next post
Why AI-Built Websites All Look the Same, and Four Levels That Fix It
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

Semantic HTML: header, nav, main, aside and footer as Page Landmarks

The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.

On this page

  • Three things run together
  • Playwright starts the app for you
  • The test is a script for the browser
  • Playwright waits until the page is ready
  • One flow passes, one fails
  • The trace shows the page at that moment
  • Keep the journeys few
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.