# E2E

> The E2E (End-to-end) testing is a type of software testing that evaluates the entire application flow from start to finish, ensuring it works as intended.

## What is end-to-end (E2E) testing and how do I write stable E2E tests?

The type of software testing that simulates real user behavior and verifies that all parts of the application work together as expected. It tests the entire flow from user input to the final result.

- Topic: Testing
- Type: approach

## Example

Wrong:

```ts
await page.click('.btn-primary');
await page.waitForTimeout(3000);
expect(await page.textContent('.msg')).toBe('Saved');
```

Right:

```ts
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByRole('status')).toHaveText('Saved');
```

Role locators match what users see, and `expect` retries until the text appears instead of sleeping a fixed time.

## Common mistakes

- Flaky tests caused by fixed sleeps instead of waiting for the UI state.
- Selectors that break when a class name changes.
- Covering every edge case with E2E tests, which makes the suite slow.

## Key points

- Elements are found by role, label or text, such as `getByRole()`, not by fragile CSS classes.
- The test waits with auto-retrying assertions, not fixed timeouts like `waitForTimeout(3000)`.
- Each test creates its own data or user and does not depend on other tests.
- Login state is set up once and reused instead of logging in through the UI in every test.

## Interview questions

### How many E2E tests should a project have?

A small number covering the most important user flows, like sign up and checkout. Put detailed logic checks in unit and integration tests.

### Why are my E2E tests flaky?

Common causes are fixed waits, shared test data, animations and network calls to real third-party services. Use auto-waiting and isolated data.

### Should E2E tests run against production?

Usually they run against a staging or preview environment. A few safe smoke checks can also run against production after deploy.

## Related cards

- [Integration Test](https://wonderium.dev/engineering/integration-test.md)
- [Screenshot Test](https://wonderium.dev/engineering/screenshot-test.md)
- [System Test](https://wonderium.dev/engineering/system-test.md)
- [ARIA Roles](https://wonderium.dev/a11y/aria-roles.md)
- [CI / CD](https://wonderium.dev/processes/ci-cd.md)

---

- Level: [Engineering](https://wonderium.dev/engineering.md)
- HTML version: https://wonderium.dev/engineering/e2e
- Last updated: 2026-11-25
