mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-25 02:24:26 +08:00
214 lines
10 KiB
Plaintext
214 lines
10 KiB
Plaintext
---
|
||
title: Debugging a run
|
||
description: Read the report, open the evidence, watch the browser, and see what the model was sent.
|
||
---
|
||
|
||
Every run writes `.e2e/report.json`. Attempt artifacts depend on the selected
|
||
engine and what it captured: screenshots, Playwright traces, downloads, or
|
||
recordings. The terminal tells you what failed; the report and the available
|
||
artifacts tell you why.
|
||
|
||
## Read the failure
|
||
|
||
The `list` reporter ends with a `Failed Tests` section: the error code, the
|
||
message, the failing line with a code frame, and what the runner saw when
|
||
the failure landed: the page's location, the nodes on screen closest to what
|
||
a failed locator asked for, and the path of the screen text. The exit code
|
||
says which side failed:
|
||
|
||
| Exit | Meaning | Retry the job? |
|
||
| ---: | --- | --- |
|
||
| 1 | A test failed | Only if the test is flaky |
|
||
| 2 | Configuration, collection, or policy | No. It is deterministic. |
|
||
| 3 | Infrastructure: the engine, the app process, the model provider, or an artifact | Yes |
|
||
| 4 | An internal runner error | Report it |
|
||
| 130 | The run was interrupted | |
|
||
|
||
## The failure pages
|
||
|
||
`--reporter list,markdown` writes `.e2e/summary.md` and, for every test that
|
||
failed or was flaky, one page under `.e2e/failures/`. The page is the
|
||
hand-off: open it before anything else.
|
||
|
||
````markdown
|
||
# ✗ todos › archives a todo
|
||
|
||
`tests/todos.e2e.ts` · failed · 16.2s
|
||
|
||
**ASSERTION_FAILED**
|
||
|
||
```text
|
||
agent.act failed: the todo exposes only a "Delete" button; no "Archive" button is present.
|
||
```
|
||
|
||
Look at: `tests/todos.e2e.ts:8`
|
||
Failed the same way on both attempts: **ASSERTION_FAILED** at step 2.
|
||
|
||
## Steps
|
||
1. ✓ `app.open` "/todos" (35ms) — `tests/todos.e2e.ts:4`
|
||
2. ✗ `agent.act` "Archive the todo" (16.1s, 6 model calls) — **ASSERTION_FAILED** — `tests/todos.e2e.ts:8`
|
||
|
||
## Agent turns of step 2
|
||
**Turn 2** `tap({"target":"n19"})`
|
||
> Tapped #n19.
|
||
> Screen changes since revision b4 (now revision b6, path /todos, 29 nodes): 4 added, 2 changed.
|
||
> added #n29 button "Delete Groceries"
|
||
|
||
## Screen at failure
|
||
URL: `http://127.0.0.1:3000/todos`
|
||
```text
|
||
#n18 textbox "New todo"
|
||
#n19 button "Add"
|
||
#n34 listitem "Groceries" testid="todo"
|
||
#n37 button "Delete Groceries"
|
||
```
|
||
````
|
||
|
||
The page has what the message cannot say. **Look at** is the line the
|
||
failure unwound through, not the line that declared the test. For an
|
||
`expect`, the block reads `Expected: … · Observed: …`; for a locator,
|
||
`Asked for: button "Add todo item" · waited 3.0s` and, under the screen, the
|
||
nodes closest to that request. **Failed the same way on both attempts** is
|
||
the difference between a bug and a flake. **Agent turns** are the last model
|
||
turns of a failed agent step: what the model called and what came back,
|
||
whatever the debug setting. **Screen at failure** is the accessibility tree
|
||
exactly as the agent reads it, one node per line, so the fix can be written
|
||
from what was there.
|
||
|
||
## The report
|
||
|
||
`.e2e/report.json` is the record the pages render from, and the one a host
|
||
ingests. `--reporter json` prints the same document on stdout.
|
||
|
||
```bash
|
||
jq '.run | {status, exitCode, errors}' .e2e/report.json
|
||
jq '.run.results[] | select(.status != "passed") | {titlePath, file, status}' .e2e/report.json
|
||
jq '.run.results[] | select(.status != "passed") | .attempts[-1]
|
||
| {status, error, failure, steps: [.steps[] | select(.status != "passed") | {api, label, source, status, error}], artifacts}' .e2e/report.json
|
||
```
|
||
|
||
Read `run.errors` first: a run-level error such as `APP_UNREACHABLE` means no
|
||
test result is meaningful. Then the last attempt of each failed result:
|
||
`error` has the code, the message, the `source` line it unwound through, and
|
||
`details` (an assertion's `expected`, `observed`, and `matches`, a locator's
|
||
`role`, `name` or `testId`, and `waitedMs`); `failure` has the `url`, the `screen` and
|
||
`screenshot` artifact ids, and the `candidates` closest to a failed locator;
|
||
each step has the `source` it was called from, and a failed agent step its
|
||
last `turns`. The `artifacts` beside them hold the files.
|
||
|
||
## Artifacts
|
||
|
||
Artifacts land under `.e2e/artifacts/`, one directory per attempt:
|
||
|
||
- **Screenshots.** The built-in `agent.assert` tries to capture one after
|
||
either verdict unless `screenshot: false` disables it. Capture can fail or
|
||
be withheld. A failed `expect` does not capture one automatically;
|
||
`app.screenshot('label')` captures one explicitly when pixels are allowed.
|
||
- **Playwright traces** when the `trace` artifact kind is enabled and capture
|
||
succeeds. Open a trace with `npx playwright show-trace <file>`.
|
||
- **Files** the app handed the test, such as a download saved through
|
||
`web.waitForDownload`; the report records them with kind `file`.
|
||
- **Videos** and **agent transcripts** when you ask for them; see below.
|
||
|
||
After a secret fill, the runner rewrites credential text in the attempt's
|
||
trace before keeping it, replacing that text with `<secret:name>`. The
|
||
report marks a successfully rewritten trace `redaction: "complete"`, but
|
||
that does not mean its pixels were redacted. Trace image resources are kept
|
||
unless they contain literal secret bytes; a secret rendered into a
|
||
screenshot frame can remain visible.
|
||
|
||
A trace inside the attempt's artifact directory that cannot be rewritten is
|
||
deleted. If an engine returns a path outside that directory, the runner
|
||
withholds the trace with `TRACE_WITHHELD` and leaves the file untouched.
|
||
|
||
Screenshots requested by agent calls and `app.screenshot()` are denied for
|
||
the rest of the attempt after a secret fill. That restriction does not stop
|
||
the screenshot frames captured inside a Playwright trace.
|
||
Videos are recorded with `redaction: "incomplete"` because a screencast masks
|
||
nothing.
|
||
|
||
## Watch it happen
|
||
|
||
```bash
|
||
npx e2e run --headed # a visible browser
|
||
npx e2e run --video # requires an engine that records video
|
||
```
|
||
|
||
`--video` requires recording support from every selected engine; an engine
|
||
without it fails configuration with `UNSUPPORTED_ARTIFACT`. Playwright writes
|
||
WebM segments under the attempt's directory, one per page it records. A
|
||
restart or state reset can produce several segments. The agent-device engine
|
||
writes an MP4 of the device screen. The failure recap names the files under
|
||
each failed test. Set
|
||
`artifacts: { kinds: ['video'], video: { retain: 'on-failure' } }`
|
||
in the config to record attempts in CI and keep only recordings from failures.
|
||
|
||
## Agent steps
|
||
|
||
Three flags look inside an agent step:
|
||
|
||
```bash
|
||
npx e2e run --debug # timings and a step table on stderr
|
||
npx e2e run --ai-trace # every model call, for a trace viewer
|
||
npx e2e run --no-cache # run the agent live instead of replaying
|
||
```
|
||
|
||
`--debug` appends two tables after the reporter's output: phase timings for
|
||
the run, and one row per agent step with its duration, model calls, tokens,
|
||
prompt-cache share, and cost when the provider reports one. Every planned
|
||
step also saves its full model transcript as an artifact.
|
||
|
||
```console
|
||
[e2e debug] agent steps (execution order, model anthropic/claude-sonnet-4.5, total $0.0312)
|
||
step total model observe action calls tokens in/out cached cost
|
||
act "add a todo named groceries" 3.9s 2.8s 410ms 620ms 3 9412/388 61% (5740) $0.0198
|
||
assert "the list shows groceries" 1.2s 1.1s 88ms 0ms 1 3120/41 0% (0) $0.0114
|
||
```
|
||
|
||
`--ai-trace` writes `.e2e/ai-trace.json` next to the report, in the AI SDK
|
||
devtools shape. Open it with [unbox-ai](https://github.com/tester-army/unbox-ai)
|
||
to see which tokens went to the system prompt, the tool definitions, or a
|
||
screen snapshot:
|
||
|
||
```bash
|
||
npx unbox-ai .e2e/ai-trace.json
|
||
```
|
||
|
||
Every agent step is one run in the trace and every model round trip one
|
||
step, with the prompt as sent, the tool definitions, the response, and
|
||
usage. Observations are redacted before the model sees them, so the trace
|
||
holds no secret the model did not. Image bytes appear as byte counts. A step
|
||
the cache replayed makes no model call and leaves no run, so pair `--ai-trace`
|
||
with `--no-cache` for a complete picture.
|
||
|
||
`--no-cache` is the first thing to try when a step that passed yesterday
|
||
fails today. A recording made against one page state can replay against a
|
||
changed one; see [Caching agent steps](/cache).
|
||
|
||
## Common errors
|
||
|
||
| Code | Usual cause | Fix |
|
||
| --- | --- | --- |
|
||
| `APP_UNREACHABLE` | Nothing answers at `url`, or `command` never became ready | Set `command.log` and read it; check the port; raise `startupTimeout` |
|
||
| `APP_ALREADY_RUNNING` | Something already serves `url` when the runner wanted to start `command` | Stop it, or set `reuseExisting: true` for local runs |
|
||
| `LOCATOR_NOT_FOUND` | Wrong role or name, text not exact, element inside an iframe, page not open | Read the markup for the accessible name; try `exact: false`; `web.frameLocator` for iframes; `--headed` to look |
|
||
| `LOCATOR_AMBIGUOUS` | Two matches: a hidden duplicate, a repeated label | Add `{ name }`, scope under a container, `filter`, `first()`, or `{ visible: true }` |
|
||
| `ASSERTION_FAILED` | The expectation is wrong, or the state settles after 5 s; for `agent.assert`, the judgment was false | Compare with the screenshot; `{ timeout }` on the matcher; rewrite the question |
|
||
| `ASSERTION_INCONCLUSIVE` | `agent.assert` asked about something the screen does not show: the value is on another page, still loading, or only in pixels | Open or wait for the right screen first; ask about what is visible; add `vision: true` when the answer is in pixels |
|
||
| `ACTION_FAILED` | Element covered, disabled, or detached, or an operation timed out | Wait on the right condition with `expect` first; close overlays |
|
||
| `STEP_BUDGET_EXHAUSTED`, `STEP_TIMEOUT` | The agent ran out of model calls or time | Scope the goal to one step; raise `timeout` for slow providers |
|
||
| `MODEL_UNAVAILABLE` | No model constructed in the config | See [Choosing a model](/models) |
|
||
| `MODEL_PROVIDER_FAILED` | Bad key, rate limit, no credits | Check the key the provider reads and the quota |
|
||
|
||
Every code, its class, and its exit code are in the
|
||
[errors reference](/reference/errors).
|
||
|
||
<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.
|
||
</Card>
|
||
</CardGroup>
|