How to Upload Snapshot Artifacts on Visual Test Failure in CI
When a visual test fails you need the expected, actual, and diff images, so upload the report as an artifact conditioned on failure.
Add an actions/upload-artifact step with if: failure() (or always()) so the diff images and HTML report are downloadable when a comparison fails.
Steps
- Run the visual tests as usual.
- Add an upload step gated on
if: failure(). - Point
pathat the report directory. - Download the artifact to inspect the diff locally.
Workflow
.github/workflows/ci.yml
jobs:
visual:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
retention-days: 7Gotchas
- The report is written only if the reporter is configured; enable the
htmlreporter. - Use
if: always()if you want the report even on green runs.
Related guides
How to Use the BackstopJS Reference, Test, and Approve Flow in CIRun BackstopJS in CI with the reference, test, and approve commands, generating baselines once and comparing…
How to Post a Visual Diff Comment on a Pull Request in CISurface visual test results on the pull request by posting a comment with a link to the diff report using act…