Skip to content
Latchkey

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: 7

Gotchas

  • Capturing traces on (always) balloons artifact size; on-first-retry keeps only the useful ones.
  • A missing trace artifact usually means no test failed, not that the upload broke.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →