End-to-End Testing
Test critical user journeys through the whole system in a real browser: selection, design, stable locators, test data, and keeping a small suite reliable.
Introduction
End-to-end (E2E) tests drive the system the way a user does: through the browser or the public API, across all layers, with real components. They give the most realistic evidence that the product works. They are also the slowest, the most fragile, and the hardest to debug.
The practical lesson is write few, choose them carefully, and make them robust. This lesson covers how.
Learning Objectives
- Decide which journeys deserve E2E tests.
- Design E2E tests around user outcomes, not UI mechanics.
- Use stable locators, explicit waits, and proper test data and isolation.
- Structure tests with page objects or equivalent helpers.
- Diagnose failures with traces, screenshots, and logs.
- Use AI to draft journeys and tests, and to review E2E suites.
1. What to Cover End to End
Cover critical journeys: the paths where failure would hurt most, and where only a full-stack test gives confidence. Limit yourself to what lower levels cannot show.
SignalDesk (illustrative) candidate journeys:
| Journey | Why E2E |
|---|---|
| Sign in, upload a CSV, see imported items listed, and see rejected rows explained | Core value; crosses UI, API, worker, and database |
| Re-upload the same file; no duplicates appear | Idempotency as the user experiences it |
| A user from workspace B cannot see workspace A’s items | Critical risk; a full-stack check of isolation |
| Create a summary and follow a claim back to its evidence | Core product promise |
| An upload fails (file too large) and the user sees a helpful error | Error path visible to the user |
Five to fifteen well-chosen journeys beat hundreds of UI-level checks. Everything else (validation rules, edge cases, permutations) belongs lower in the pyramid.
2. Design Tests Around Outcomes
Write the test as a user story, using domain language, and assert user-visible outcomes.
1
2
3
4
5
6
7
8
9
def test_member_imports_feedback_and_sees_rejected_rows(page, signed_in_member):
page.goto("/imports/new")
page.set_input_files("input[type=file]", "fixtures/feedback_with_two_bad_rows.csv")
page.get_by_role("button", name="Import").click()
expect(page.get_by_text("Import complete")).to_be_visible()
expect(page.get_by_test_id("imported-count")).to_have_text("8")
expect(page.get_by_test_id("rejected-count")).to_have_text("2")
expect(page.get_by_text("Row 4: Feedback text is missing")).to_be_visible()
Principles:
- Assert what the user sees, not the DOM’s internals.
- One journey per test, with a clear name.
- Keep the steps few; shortcuts such as logging in through the API or seeding data directly make tests faster and more focused. Test the login journey itself once.
- Do not test the same thing in many E2E tests.
3. Stable Locators
Brittle locators are the most common cause of E2E maintenance pain. Prefer, in order:
- Role and accessible name (
buttonnamed “Import”): resilient, and encourages accessible markup. - Visible text or labels for user-facing elements.
- Dedicated test attributes (
data-testid) where no meaningful role or text exists. - Avoid long CSS or XPath chains tied to layout, and indexes like “the third div.”
Treat test IDs and accessible roles as part of the product’s contract with its tests.
4. Waiting and Timing
Most “flaky” E2E tests are timing problems.
- Use auto-waiting and explicit conditions (“wait until the element is visible”, “until the job status is Complete”), not fixed sleeps.
- Wait for the business condition, not the clock. For the background import, poll the status with a generous timeout rather than sleeping ten seconds.
- Set sensible timeouts and fail with a message that says what was awaited.
- Control time and external services where possible: a stubbed model provider, a fake clock for scheduled behavior.
5. Test Data and Isolation
- Each test creates its own data (a fresh workspace and user) so tests do not interfere and can run in parallel.
- Seed through APIs or database helpers, not through slow UI steps.
- Clean up or discard environments; prefer disposable environments over cleanup code.
- Use synthetic data only; never production data.
- Keep fixture files small and purposeful, named by what they test.
6. Structure: Page Objects and Helpers
Encapsulate page interactions so that a UI change requires one fix, not fifty.
1
2
3
4
5
6
7
8
9
10
11
class ImportPage:
def __init__(self, page): self.page = page
def upload(self, path):
self.page.goto("/imports/new")
self.page.set_input_files("input[type=file]", path)
self.page.get_by_role("button", name="Import").click()
def summary(self):
return {
"imported": int(self.page.get_by_test_id("imported-count").inner_text()),
"rejected": int(self.page.get_by_test_id("rejected-count").inner_text()),
}
Keep assertions in the tests, and interaction details in the helpers. Do not build a heavy framework before you need one.
7. Diagnosing Failures
An E2E failure should tell you quickly whether the cause is the product, the test, or the environment. Configure the tooling to capture, on failure:
- Screenshots and video of the browser.
- A trace (steps, network calls, console messages).
- Application logs and the request ID correlated with the test.
- The test data created, for reproduction.
Retry policy: a single automatic retry can reduce noise but also hides flakiness. If you allow it, record every retry and treat tests that need retries as defects to fix (lesson 8).
8. Other Forms of End-to-End Testing
- API-level journeys (without a browser) are faster and often sufficient for backend flows.
- Accessibility checks can be automated for common issues (missing labels, contrast), but cover only a portion of real accessibility; combine them with keyboard and screen-reader exploration.
- Visual regression compares screenshots; it is useful for stable, design-critical pages but generates noise on dynamic content.
- Synthetic monitoring runs a reduced journey continuously in production to detect problems early.
9. Using AI for End-to-End Testing
AI can draft journey lists and test code, and review the suite for weaknesses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Act as a test architect.
Inputs:
- Product description and main user journeys: [paste]
- Risk table: [paste]
- Existing automated tests by level: [paste]
Tasks:
1. Propose the smallest set of end-to-end journeys that covers the
Critical and High risks that cannot be adequately covered at lower
levels.
2. For each journey give: goal, preconditions, steps, user-visible
assertions, and the test data required.
3. List scenarios that I might be tempted to test end to end but
should test at a lower level, and where.
4. Identify likely sources of flakiness in each journey and how to
avoid them.
When asking for test code, supply your locator conventions and helper classes, and require role-based locators and explicit waits. Reject generated tests with sleeps, brittle selectors, or assertions on implementation details.
10. Practical Exercise
For SignalDesk (or your project):
- Choose five journeys using the risk table, and justify why each needs E2E.
- Write E2E tests for them using stable locators, explicit waits, and isolated data created per test.
- Introduce a helper (page object) for the import page, and refactor one test to use it.
- Configure failure artifacts (screenshot, trace, logs) and force a failure to confirm they help you diagnose it.
- Run the suite ten times, record the pass rate, and fix any intermittent failures.
- Run the AI prompt, verify its suggestions, and move at least one scenario down to a lower level if appropriate.
Verification
You are ready to continue when:
- The E2E suite covers the critical journeys and little else.
- Tests use role or test-id locators and no fixed sleeps.
- Each test creates and owns its data.
- A deliberate failure produces enough evidence to diagnose it.
- Ten consecutive runs produce consistent results.
Key Takeaways
- E2E tests give the most realistic evidence and the highest cost; keep them few.
- Test journeys and user-visible outcomes, not UI mechanics.
- Stable locators, explicit waits, and isolated data remove most flakiness.
- Capture traces and screenshots so failures can be diagnosed quickly.
- Push everything that can be tested lower down the pyramid.
What’s Next?
Tests only provide value if they run, constantly and reliably. Next, we look at test automation: pipelines, speed, flakiness, and keeping the suite healthy over time.