Course contentsShow
← React
Lesson 2202 of 2,39648. End-to-End TestingFree lesson

Handling Test Artifacts and Screenshots

Configure CI to capture and upload screenshots, videos, and traces when tests fail for debugging purposes.

Handling Test Artifacts and Screenshots

You'll learn: How to configure CI pipelines to automatically capture and preserve test artifacts like screenshots, videos, and traces when E2E tests fail, making debugging remote failures much easier.

Why Test Artifacts Matter in CI

When a test passes locally but fails in CI, you're left guessing what went wrong. Unlike running tests on your machine where you can see the browser, CI runs headlessly in the cloud. Test artifacts—screenshots, videos, and execution traces—are your eyes into what actually happened during that failed test run.

Think of artifacts like a car's dashcam: you don't need it when everything goes smoothly, but when there's an incident, that recording becomes invaluable evidence.

Configuring Artifact Capture

In GitHub Actions with Playwright, you configure artifact collection in your workflow file. Playwright automatically captures screenshots and traces on failure when properly configured:

- name: Run Playwright tests
  run: npx playwright test
  
- name: Upload test artifacts
  if: failure()
  uses: actions/upload-artifact@v3
  with:
    name: playwright-report
    path: |
      playwright-report/
      test-results/
    retention-days: 30

The if: failure() condition ensures artifacts only upload when tests fail, saving storage costs. The retention-days setting controls how long GitHub keeps these files.

What Gets Captured

Playwright's test-results/ directory contains screenshots taken at the moment of failure, videos of the entire test run, and trace files you can replay in the Trace Viewer. These artifacts let you see exactly what the page looked like, what actions were taken, and what network requests occurred—all without reproducing the failure locally.

Key Takeaway: Configuring CI to capture screenshots, videos, and traces on test failure transforms cryptic CI errors into debuggable evidence, dramatically reducing the time spent investigating remote failures.