Artifacts and reports
Artifacts are the traces, screenshots, videos and reports left from a run once the browser is gone. A typical CI setup is trace on-first-retry with retries, screenshots only on failure, and video only where needed. The report upload runs under always() or !cancelled(), otherwise it is skipped after the tests fail. Playwright clears the test-results folder at the start of every run.
Playwright · Debugging
The test is red on CI and the report is empty: no trace, screenshot or video. What went wrong?
A test failed on CI, the developer opens the pipeline and finds neither a report nor a trace: the upload step did not run because the previous one was red. Artifacts are everything that remains of a run when the browser is gone: traces, screenshots, videos, reports, attached data. They are configured on the principle "enough to investigate, but no more expensive than needed": recording every trace across thousands of tests slows the run down and fills the storage. This lesson covers what Playwright creates, where it puts it and how to make sure it survives a failure.
How it works and why. There are two different places. Test artifacts (traces, screenshots, videos) go to outputDir, test-results by default, into a separate subfolder per test and attempt. Playwright cleans this folder at the start of every run, so old results do not pile up, but they do not survive the next run either. Reporters write separately: the HTML reporter to playwright-report, JUnit to the file you name, blob to blob-report. The report and results folders must be different. The HTML reporter copies the tests' traces, screenshots and videos into the report's data subfolder, so the playwright-report folder is self-contained: it can be uploaded and opened apart from test-results.
The path of an artifact from a test to a developer
What to record. It is configured in use:
| Option | Useful values | Cost |
|---|---|---|
| trace | on-first-retry, retain-on-failure, on | Medium: DOM snapshots |
| screenshot | only-on-failure, on | Low |
| video | retain-on-failure, on-first-retry | High: the heaviest artifact |
on-first-retry writes an artifact only on the first retry, so without retries it gives nothing. retain-on-failure always writes but keeps only for failed tests: more expensive, but the artifact exists even without retries. A typical CI scheme: trace: 'on-first-retry' and screenshot: 'only-on-failure', with video switched on selectively. The trace option also accepts an object if you need to control what is recorded:
use: {
trace: { mode: 'retain-on-failure', screenshots: true, snapshots: true, sources: true },
video: 'retain-on-failure',
},
outputDir: 'test-results', // traces, videos and screenshots go here
Example: the report vanished together with the failure. A step without a condition:
# before: after a red tests step this step will not run
- run: npx playwright test
- uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
By default a step runs only if all previous ones succeeded. The test failed, the upload step was skipped, and the pipeline is red with no artifacts at all. The fix is a condition that runs the step always:
# after: upload the report and the results always
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: |
playwright-report/
test-results/
retention-days: 14
Instead of always() people often take !cancelled(): artifacts are kept, and a manually cancelled run does not waste time uploading. The retention period (retention-days) keeps the storage under control. If there are many tests split into shards, each shard uploads a blob report under a unique name and a separate step merges them with merge-reports; that is covered in the lesson “CI: sharding, Docker and fast reruns”.
The upload step after tests fail
No condition
The tests step is red and the next ones are skipped. There is no report or trace, and the investigation starts with a rerun.
With always()
The upload runs after a failure: the report and trace wait in the pipeline for the developer to open them.
Reporters. Several can be used at once, and the set depends on the environment:
reporter: process.env.CI
? [['blob'], ['junit', { outputFile: 'results/junit.xml' }], ['github']]
: [['html', { open: 'on-failure' }], ['list']],
| Reporter | What it is for |
|---|---|
html | A report for people with traces, screenshots and a flaky filter |
list, dot | Console output |
junit | Integration with Jenkins, GitLab and other CI systems |
github | Error annotations right in the PR |
blob | A shard report for later merging |
For Allure you add the allure-playwright package.
Your own data in the report. Through testInfo.attach you add everything that helps investigate a failure: API responses, logs, generated files. A file from disk is attached with the path parameter instead of body.
test('statement reconciliation', async ({ request }, testInfo) => {
const res = await request.get('/api/statement');
await testInfo.attach('statement', {
body: await res.text(),
contentType: 'application/json',
});
expect(res.ok()).toBeTruthy();
});
Steps. test.step groups actions in the report and the trace under clear names, so a long scenario reads as a set of business steps, and a failure highlights exactly the step where the test stopped:
await test.step('The client submits a request', async () => {
await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.getByText('Request accepted')).toBeVisible();
});
Limits and alternatives. Artifacts do not replace server logs: they show what the browser saw. Video takes the most space and gives the least: the trace shows the same with the DOM and network, so video is switched on when a failure has to be shown to people outside the team. In Cypress, cypress run keeps screenshots on failure by default, while video is turned on with video: true, in Selenium artifacts are collected by your own code in hooks.
Common mistakes.
trace: 'on'in a large suite: gigabytes of artifacts and slower runs.on-first-retrywithoutretries: there are no artifacts, and the developer does not understand why.- An upload step without
always()or!cancelled(): the report disappears exactly on a failure. - The same artifact name in all shards: they overwrite each other.
- Attaching secrets (tokens, passwords): the whole team sees the report.
Check yourself
The npx playwright test step is red. The next step uploading playwright-report has no condition. What will happen in the pipeline?
Answer
The upload step will not run: by default the following steps start only after successful ones. There will be no report or trace in the pipeline, exactly what had to be saved. Add if: always() or !cancelled().
You run the tests twice in a row locally and notice that the trace of the first run has vanished from test-results. Is it a bug?
Answer
No. Playwright cleans outputDir at the start of every run. If a result has to be kept, copy it elsewhere or upload it as a CI artifact before the next run.
Why is retain-on-failure better for a long flaky scenario, while video is switched on only selectively?
Answer
retain-on-failure keeps the trace of every failed attempt, including the first, and keeps only those, so no space is wasted. Video is the heaviest, and a trace with the DOM and network allows a more precise investigation, so video is taken when a failure has to be shown to people outside the team.
trace: 'on-first-retry' with retries, screenshots only on failure, and I upload the report and test-results with a separate step using always(). Middle/Senior: The reporter set depends on the environment: blob for shards with later merging, JUnit for the CI system, github for PR annotations, HTML locally. I do not make artifacts more expensive than needed: video only selectively, retention-days limited, shard artifact names unique. I attach extra data such as API responses through testInfo.attach, but never secrets, because the whole team sees the report.