Debugging failures
toets failures are meant to explain themselves. Read what they say before changing the test.
1. Read the failure
- The error. A thrown error reads
ToetsError: [CODE] what happened, thenHint:(likely cause and fix) andDocs:(the page, with its offline path). Every code is listed in the error code index. A failed assertion shows the locator, expected and received state, what was focused and whether the app was idle. - The failure dump (
toets-failure.md, withtoets-screenshot.png), in the failed test'stest-results/folder and attached to the report: platform and capabilities, the focused element, a text snapshot of the screen, the last keys pressed, what kept the app busy, recent logs and requests. See failure dumps. - The report.
npx playwright show-reportlists every action as a step (press RIGHT,pressUntilFocused RIGHT getByTestId('card')). Per test:toets-logsand, with mocking on,toets-network.har. Per-step screenshots and snapshots (toets.steps) and video (toets.video) are off by default; turn them on while debugging. Web runs also record Playwright traces (--trace on).
2. Reproduce narrowly
sh
npx playwright test e2e/home.spec.ts:12 --project=android-tv --retries=0
npx playwright test e2e/home.spec.ts --project=web --ui
npx playwright test e2e/home.spec.ts --repeat-each=10 # is it flaky?To look at the live app with the same primitives, use the MCP server: launch, press, snapshot.
3. Match the symptom
| Symptom | Look at |
|---|---|
| Element not found on one platform | The text snapshot: is the test ID there? See the test ID mapping in Locators. |
| Focus on the wrong element | The step screenshots and last keys. An overlay or a different focus engine rule on that platform. |
FOCUS_STUCK, FOCUS_LOOP, FOCUS_UNREACHABLE | Where focus went, in the message. Stuck: end of a row, a trap, a disabled target. Loop: the target is not in that direction. |
| Timed out, busy resource named | The app never went idle: a poller, animation or player. Exclude the noise in the SDK. |
KEY_UNSUPPORTED | The platform lacks it. Declare requires, or configure an override. See Remote and keys. |
| Negative assertion passes, then the bug appears | It passed too early. Anchor it on a positive assertion. See Idle. |
| Passes on web, fails on a device | Compare text snapshots across platforms; check device logs for app errors. |
| Launch fails | Driver and device logs; the app config for that platform; see Platforms. |
Traps
- Do not raise the timeout unless the operation is legitimately slow. Most timeouts are wrong state, not slowness.
- Do not add sleeps or retries to make a flaky test pass. Find what the test raced against.
- Do not weaken the assertion to match buggy behavior. If the app is wrong, the test should keep failing; report the bug.
- Check the app first when a test that used to pass fails everywhere at once.