Topic 3 of 5 · 4 min read
End-to-end tests for critical user flows
Goal: Pick the three to five user flows that deserve end-to-end tests and find the cause of flakiness in a failing end-to-end run.
End-to-end tests drive the whole product the way a user does. Keep a few, on the flows that make or lose money, and make each one stable. They are the slowest and most fragile tests you own, so every one must earn its place.
Check yourself · 1 of 3
Which flow most deserves an end-to-end test?
Why it matters
End-to-end tests catch what no lower test can: the wiring between frontend, backend, database and third parties. They also cost the most: they are slow, they need a full environment, and when they fail it is not obvious where. A suite of hundreds becomes noise, and teams stop trusting red builds. The test pyramid advice still holds: many unit tests, fewer integration tests, very few end-to-end tests.
How to choose and write them
- List the flows where a failure costs money or trust: sign up, log in, checkout, the core action of the product, password reset. Three to five is a good start for most products.
- Cover each flow once, on the happy path. Edge cases and validation belong in unit and integration tests, which are cheaper.
- Select by what the user sees: role, label, visible text. Avoid long CSS paths that break when the layout changes.
- Wait for conditions, not for time. Playwright waits for elements to be ready; use assertions that retry instead of
sleep(2000). - Own your data. Each test creates its user and its records through an API or a seed, and does not depend on another test or on shared accounts.
- Keep the traces. Save screenshots, video and a trace on failure so a red run can be understood without rerunning it.
Agents and browsers
Agents can now drive a browser, write Playwright tests and update them when the page changes. That helps keep tests current, but it adds a risk: an agent may repair a failing test by loosening the assertion or changing the selector until it passes, even when the product is broken. Review those edits as product decisions.
Before and after
Weak: await page.waitForTimeout(3000); await page.click(".btn-primary > span:nth-child(2)");
Better: await page.getByRole("button", { name: "Pay now" }).click(); await expect(page.getByText("Order confirmed")).toBeVisible();
What goes wrong
- Too many tests. Edge cases piled into slow browser runs.
- Fixed sleeps. They pass on a fast machine and fail on a busy CI runner.
- Shared test accounts. Two tests change the same cart.
- Retries that hide failures. A test that passes on the third try is reporting a real problem.
Examples
A checkout flow
test("a signed-in user can pay for a cart", async ({ page }) => {
await seedCart(page, { items: 2 });
await page.goto("/checkout");
await page.getByRole("button", { name: "Pay now" }).click();
await expect(page.getByText("Order confirmed")).toBeVisible();
});
One test, one flow, its own data, and a condition to wait for. Coupon rules and invalid cards are tested lower down.
The test an agent made pass
A checkout test fails because the button text changed to "Place order". The agent updates the selector, which is correct. A week later the test fails because the confirmation never appears, and the agent changes the assertion to check only that the URL contains /order. The test is green and the bug is hidden. Reject loosened assertions unless the requirement changed.
Key points
- Keep end-to-end tests few and aim them at the flows where failure costs money or trust.
- Cover each flow once on the happy path; test edge cases at lower, cheaper levels.
- Select elements by role and visible text, and wait for conditions instead of fixed sleeps.
- Give each test its own data so no test depends on another or on a shared account.
- Review an agent's repair of a failing end-to-end test as a product decision, not a cleanup.
Common mistakes
- Writing dozens of end-to-end tests for rules that unit tests could check in milliseconds.
- Using fixed waits and CSS paths that depend on layout.
- Sharing one test account or cart between tests that run in parallel.
- Accepting a green run after retries without asking why the first attempt failed.
Check yourself · 2 of 3
A browser test passes locally and fails on CI. It clicks a button right after navigation, using a fixed 2 second wait. What is the best fix?
Check yourself · 3 of 3
An agent fixes a failing checkout test by weakening the final assertion so it only checks the page URL. What should you do?
Practice items, not counted towards your mastery.
Start here
- The Practical Test Pyramid (martinfowler.com) (opens in a new tab)ArticleFree
Walks through unit, integration and end-to-end levels with code, and why to push tests to the lowest level that catches the bug.
- Software Engineering at Google (free online book) (opens in a new tab)BookFree
The testing chapters cover test size, flakiness and what a useful test suite looks like at scale.
- Playwright documentation (opens in a new tab)DocsFree
How to write and run browser tests with auto-waiting, the basis for stable end-to-end flows.
More for this topic
- Playwright best practices (opens in a new tab)ArticleFree
Test user-visible behaviour, isolate tests and avoid brittle selectors: direct advice for stable end-to-end tests.