How to Upload Playwright Traces and Videos on Failure in GitHub Actions
Set trace, video, and screenshot to on-first-retry / retain-on-failure, then upload the results directory when the job fails.
Configure trace: 'on-first-retry' and video: 'retain-on-failure' so artifacts appear only for failures, then upload test-results/ with if: failure().
Steps
- Set trace/video/screenshot capture modes in the config.
- Run the suite with retries enabled.
- Upload
test-results/(and the HTML report) on failure. - Open a trace locally with
npx playwright show-trace.
playwright.config.ts
playwright.config.ts
import { defineConfig } from '@playwright/test'
export default defineConfig({
retries: 2,
use: {
trace: 'on-first-retry',
video: 'retain-on-failure',
screenshot: 'only-on-failure',
},
})Workflow upload
.github/workflows/ci.yml
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-traces
path: test-results/
retention-days: 7Gotchas
- Capturing traces
on(always) balloons artifact size;on-first-retrykeeps only the useful ones. - A missing trace artifact usually means no test failed, not that the upload broke.
Related guides
How to Retry Flaky E2E Tests in GitHub ActionsReduce flaky E2E failures in GitHub Actions by enabling framework-level retries in Playwright or Cypress so a…
How to Run Playwright Tests in CI on GitHub ActionsRun Playwright end-to-end tests on GitHub Actions by installing browsers with their OS dependencies, running…