> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Debugging a run

> Debug a failed end-to-end test with its trace page, the screenshot and app log at the failure, a headed rerun, stepping through the test, and the agent's model calls.

A failed test prints its error and the path to its trace page. Work through
the steps below in order and stop at the one that explains the failure.

## Read the failure

The `list` reporter's `Failed Tests` section shows the error, the failing
line, nearby matches for a failed locator, what the app logged, and the
trace page:

```text
 FAIL  |web| tests/todos.e2e.ts > shows the remaining count
LOCATOR_NOT_FOUND: locator did not become visible: getByRole("heading", name: "Todos")
 ❯ tests/todos.e2e.ts:31:3
 ❯ at http://127.0.0.1:4271/nope
 ❯ app 2 errors, 2 warnings logged
   × console error: Error occurred prerendering page "/todos"
   × network error: GET /api/todos 500 Internal Server Error
 ❯ trace .e2e/results/todos-shows-the-remaining-count-796fac5f12ab34cd/trace.md
```

The error code names the cause, and
[Common errors](https://e2e.com/docs/reference/errors#common-errors) has the usual cause and fix
for each one. The [exit code](https://e2e.com/docs/reference/errors#exit-codes) tells the type
of failure and whether a retry can help.

For a summary of the whole run, add the
[`markdown`](https://e2e.com/docs/reference/reporters#markdown) reporter, which writes
`.e2e/summary.md`. A script reads the same facts from
[`report.json`](https://e2e.com/docs/reference/reporters#report-json).

<a id="traces" />

## Open the trace page

By default, each failed, timed out, interrupted, or flaky test gets a trace
page, `trace.md`, in its directory under `.e2e/results/`. Open it in an
editor's markdown preview so its links work. It lists every step with what
it did, then the app log, the agent's last turns, and the screen at failure.

<Accordion title="Example trace page">

````markdown
# ✗ todos › shows the remaining count

`tests/todos.e2e.ts` · failed · 2.2s

**ASSERTION_FAILED**

```text
expect.toHaveText failed
locator: getByRole("status", name: "Remaining")
expected: text "1 remaining"
observed: text "0 remaining" (match count 1)
```

Ran on: browser `chromium 141.0.7390.37` · user agent `Mozilla/5.0 (Macintosh; …) HeadlessChrome/141.0.7390.37 Safari/537.36`

Look at: `tests/todos.e2e.ts:15`

## Steps

1. ✓ `app.open` `/todos` (37ms in beforeEach) — `tests/todos.e2e.ts:4`
2. ✓ `agent.act` "Add a todo named Milk." (429ms, 2 model calls) — `tests/todos.e2e.ts:12`
   - cache: no replay: nothing recorded for this step yet; recording saved (`.e2e/cache/1227d5a6….json`)
   - type "Milk" into textbox "New todo" (17ms)
   - press "Enter" on the focused field (5ms)
   - ✗ network error: `POST /api/todos 500 Internal Server Error`
   - screen: 6 changes since step 1 at `/todos`, 38 nodes
     - `added listitem "Milk Delete Milk" testid="todo"`
     - `added checkbox "Milk"`
     - `changed status "Remaining" text="1 remaining" (was: status "Remaining" text="0 remaining")`
     - 3 more
3. ✓ `locator.check` `getByLabel("Milk")` (13ms) — `tests/todos.e2e.ts:14`
   - check checkbox "Milk" (13ms)
   - screen: 3 changes since step 2 at `/todos`, 38 nodes
     - `added checkbox "Milk" [checked]`
     - `changed status "Remaining" text="0 remaining" (was: status "Remaining" text="1 remaining")`
     - `removed checkbox "Milk"`
4. ✗ `expect.toHaveText` `getByRole("status", name: "Remaining")` (1.6s) — **ASSERTION_FAILED** — `tests/todos.e2e.ts:15`
   - expect gave up after 16 reads in 1.6s: text "0 remaining" (1 match) x16

## App log

What the app logged, oldest first, with the step it happened in.

- step 2 · ✗ network error: `POST /api/todos 500 Internal Server Error`

## Screen at failure
`http://127.0.0.1:4271/todos` · viewport 1280x720 · 38 nodes

![screenshot at failure](attempt-1/screenshots/001-failure.png)

```text
#n29 textbox "New todo"
#n30 button "Add"
 #n35 listitem "Milk Delete Milk" testid="todo"
  #n36 checkbox "Milk" [checked]
#n40 status "Remaining" text="0 remaining"
```
````

</Accordion>

`--trace` keeps a page for every test of a run, passing ones included. See
[`trace`](https://e2e.com/docs/reference/config#trace) for the modes and
[What a trace page holds](https://e2e.com/docs/reference/config#what-a-trace-page-holds) for
each part.

## Look at the screen and the app log

The **Screen at failure** section has the screenshot and the semantic tree
the test saw. Compare them with the locator or the expectation that failed.

The **App log** section has the app's console output, uncaught exceptions,
and failed requests, each with its step. Check it when an assertion read the
same wrong value the whole time: a failed request often explains it. An
assertion whose readings changed raced the app.

<a id="artifacts" /><a id="console-output" />

The screenshot, any video, and downloads are files in the test's directory.
[What a run captures](https://e2e.com/docs/reference/config#what-a-run-captures) lists them. A
`console.log` in the test prints while it runs, under a
[heading that names the test](https://e2e.com/docs/reference/reporters#console-output).

## Watch it happen

Rerun the test with a visible browser. Add `--video` to record the run.

<CodeGroup>
```bash npm
npx e2e run tests/todos.e2e.ts --headed
```

```bash pnpm
pnpm exec e2e run tests/todos.e2e.ts --headed
```

```bash bun
bunx e2e run tests/todos.e2e.ts --headed
```
</CodeGroup>

Each recording goes into its attempt's directory, and the failure recap
prints its path. In CI, set `video: 'on-first-retry'` in the config. A test
that passes the first time records nothing, and a flaky test leaves a
recording of its retry.

[Recording](https://e2e.com/docs/reference/config#recording) has every mode, which setting wins,
and what happens on an engine that can't record.

## Step through a test

`--step` runs the first step, then holds each later step until you press a
key. Add `--headed` to watch the browser between steps.

<CodeGroup>
```bash npm
npx e2e run tests/checkout.e2e.ts --step --headed
```

```bash pnpm
pnpm exec e2e run tests/checkout.e2e.ts --step --headed
```

```bash bun
bunx e2e run tests/checkout.e2e.ts --step --headed
```
</CodeGroup>

At the prompt, Enter runs the held step, `s` shows the screen, `l` shows the
app log, and `q` stops the run. Paused time doesn't count against step,
test, or run timeouts. [Step mode](https://e2e.com/docs/reference/cli#step-mode) lists every key and what runs
without pausing.

<a id="step-through-a-test-without-a-terminal" />

Without a terminal, as in a coding agent's shell, `--step` runs the test in
the background and returns at the first held step with its screen. Run
`e2e run --step next` for each later step, `--step rest` to run the rest, or
`--step stop` to end the run. See
[Step commands](https://e2e.com/docs/reference/cli#step-commands).

## Pause a test

With [`screen.pause()`](https://e2e.com/docs/reference/screen#screen-pause), you can pause the
test at a line, with the app open, until you resume it. The test is paused
each time the line runs, such as on every pass of a loop.

```ts title="tests/checkout.e2e.ts"

test('pays with a card', async ({ app, screen }) => {
  await app.open('/checkout');
  await screen.pause();
});
```

Run the test with `--headed` to look at the browser while it's paused. Press
Enter to resume, or `s` and `l` for the screen and the app log, as at a
`--step` prompt. Without a terminal, resume with `e2e run --step next` from
another shell in the same directory. In CI, `screen.pause()` fails the test
immediately, so remove it before committing.

<a id="agent-steps" />

## Check what the model was sent

Rerun an `agent.act` or `agent.assert` step live and record what the agent
did:

<CodeGroup>
```bash npm
npx e2e run tests/todos.e2e.ts --no-cache --debug --ai-trace
```

```bash pnpm
pnpm exec e2e run tests/todos.e2e.ts --no-cache --debug --ai-trace
```

```bash bun
bunx e2e run tests/todos.e2e.ts --no-cache --debug --ai-trace
```
</CodeGroup>

`--debug` prints a table with one row per agent step: duration, model
calls, tokens, prompt-cache share, and cost when the provider reports one.
See [Debug output](https://e2e.com/docs/reference/cli#debug-output).

`--ai-trace` writes `.e2e/ai-trace.json` with every model call. Read it with
unbox-ai, as [Output](https://e2e.com/docs/reference/cli#output) shows, to see the prompts and
tool calls. A replayed step makes no model call and leaves no AI trace, so
`--no-cache` traces the whole flow and rules out a stale
[recording](https://e2e.com/docs/cache). [Agent steps](https://e2e.com/docs/agent-steps) explains what the model
sees and may do.

## Next

<CardGroup cols={2}>
  <Card title="CLI reference" icon="terminal" href="/reference/cli#e2e-run">
    Every flag of `e2e run`.
  </Card>
  <Card title="Errors" icon="triangle-exclamation" href="/reference/errors">
    Every error code, with common causes and fixes.
  </Card>
</CardGroup>
