Playwright error-context.md: what is in it and how to use it with AI agents
By Sekhar · October 31, 2026 · 5 min read
In short
- When a test fails, Playwright 1.63 writes
error-context.mdinto that test's folder undertest-results/and attaches it to the result. The list and line reporters print its path as "Error Context:". - It is a Markdown prompt for fixing the test: instructions, the test name and location, the error, an accessibility snapshot of the page at the time of failure, and up to 100 lines of test source on each side of the failing line.
- Coding agents can read it instead of the whole terminal output. It holds page text and code, so treat it like a trace: keep it out of public artifacts.
- It explains one failure in one run. It does not say whether the test was already failing on main or has been flaky for weeks.
Where the file comes from
At the end of a test that has errors, Playwright builds an error context and writes it to error-context.md in the output folder of that test, the same folder where screenshots, videos and traces go (for example test-results/login-shows-error-chromium/error-context.md). It is attached to the test result as error-context with type text/markdown, so reporters that show attachments carry it.
In the terminal, the list and line reporters do not print the whole file. They print a pointer under the failure:
Error Context: test-results/login-shows-error-chromium/error-context.md
That line is why people search for it: it shows up under every failure, and it is not obvious what the file is for.
What is inside
Playwright 1.63 writes these sections, in this order:
- Instructions. Three lines addressed to an assistant: the test failed, explain why concisely following Playwright best practices, and provide a code fix if possible.
- Test info. The full test name (file, describe blocks and title joined with
>>) and its location,file:line:column. - Error details. Each error message in a code block, without color codes. When the failure came from an assertion that supplies its own context, such as an aria snapshot match, that context is added as YAML.
- Page snapshot. An accessibility snapshot of the first open page, in YAML, taken after the failure and before the page was closed. It lists roles, names and text of what was on screen, which is often enough to see that the button had a different label or a dialog was in the way.
- Test source. The source file around the line where the error was thrown: up to 100 lines above and below, with the failing line marked
>and a caret under the error position.
Sections without data are left out. A test that failed before any page opened has no page snapshot; a failure without a usable stack has no source section. If there is no error message and no snapshot, no file is written.
Turning off the page snapshot
In 1.63, setting the environment variable PLAYWRIGHT_NO_COPY_PROMPT stops Playwright from taking the page snapshot for this file. The rest of the file is still written. The HTML reporter has a related noCopyPrompt option (or PLAYWRIGHT_HTML_NO_COPY_PROMPT) for its own report.
Using it with a coding agent
The file is built to be pasted, or read directly, by an AI assistant. Compared with the raw terminal output it is short, structured and has the page state, which an agent cannot otherwise see after the browser has closed. A practical loop:
- Run the failing test:
npx playwright test tests/login.spec.ts. - Give the agent the path printed after "Error Context:" and ask for the cause before any fix.
- Check the proposed fix against the page snapshot: does the locator it suggests exist there?
- Re-run the test, ideally with
--repeat-each=5, so a fix that only hides a race is caught.
Be careful with the kind of fix agents tend to propose. A longer timeout, a waitForTimeout, a looser assertion or test.skip will make the file go away without fixing anything. The guide to reviewing AI-written Playwright tests lists what to look for.
Playwright also changes some behavior when it detects a coding agent. In 1.63 it checks the CLAUDECODE and COPILOT_CLI environment variables, and when either is set the HTML reporter does not try to open a browser at the end of the run. See why the HTML report did not open.
What to keep out of it
The page snapshot contains the text that was on the page: names, emails, order numbers, anything your test account could see. The source section contains your test code, including any value written in it. If test-results/ is uploaded as a CI artifact, everyone who can read the artifacts can read these files.
- Use test accounts with fake data, and never hard-code credentials in test files; read them from environment variables.
- Keep CI artifacts private and short-lived, or set
PLAYWRIGHT_NO_COPY_PROMPTin CI if you do not need the snapshot there. - Treat it like a trace. The guide to keeping secrets out of Playwright traces covers the same risks for traces and screenshots.
What one error context cannot tell you
The file is good at one question: why did this test fail just now? The questions after a red pull request are often different. Did my change cause it, or was it already failing on main? Has it failed like this before? An agent that reads one error context will try to fix the test even when the failure is a known flaky one that has nothing to do with the change.
TurnSignal answers those across runs: each failure is labelled new, also failing on main or known flaky, with the error, screenshot and trace one click away. Coding agents can ask the same questions through its MCP server before they change a test. See the docs.
Questions people ask
Can I delete error-context.md files?
Yes. They live in test-results/, which Playwright clears at the start of each run anyway. Nothing reads them back.
Why is there no page snapshot in my error-context.md?
Either the test had no open page when it failed (for example an API-only test), the snapshot could not be taken within 5 seconds, or PLAYWRIGHT_NO_COPY_PROMPT is set.
Is error-context.md written for passing tests?
No. It is only written when the test has errors. A flaky test gets one for its failed attempt, in that attempt's output folder.
Where is it written when I change outputDir?
In the test's own subfolder of your outputDir. Playwright creates a unique subfolder for each test so parallel tests never write to the same place.
Sources
- Playwright 1.63 source: buildErrorContext (errorContext.ts)
- Playwright 1.63 source: writing error-context.md (index.ts)
- Playwright docs: Aria snapshots
- Playwright docs: Test configuration (outputDir)
Playwright details were checked against Playwright 1.63 and its documentation on October 31, 2026.
Try TurnSignal on your next run
Add one reporter line next to your existing reporters. Free to start, no credit card, no repository access.