# test/test_helper.rb
require 'capybara_screenshot_diff/static'
CapybaraScreenshotDiff.serve("_site") # or "public", "build", "dist"This sets up Capybara to serve static files and configures screenshot paths automatically.
See the Quick Start section in the README for recommended .gitignore patterns.
Only commit the baseline screenshots (e.g., homepage.png). The .base.png, .diff.png, .heatmap.diff.png, and report files are regenerated on every test run.
Add to your test helper:
require 'capybara_screenshot_diff/reporters/html'The simplest way — one step handles artifact upload, job summary, and PR comments:
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # Required for PR comments
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run tests
run: bundle exec rake test
- name: Upload screenshot reports
if: failure()
uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
with:
name: screenshots
pr-comment: 'true'That's it. On failure, this will:
- Upload diff images + HTML report as artifacts
- Post a PR comment with links to the inline report and full artifact download
- Add a job summary with report links (visible in the Actions UI)
| Input | Default | Description |
|---|---|---|
name |
(required) | Artifact name prefix |
report-path |
doc/screenshots |
Path to HTML report directory |
retention-days |
2 |
Days to retain artifacts |
pr-comment |
false |
Post PR comment with report link (requires pull-requests: write) |
| Output | Description |
|---|---|
report-url |
Direct URL to the inline HTML report artifact |
report-full-url |
Direct URL to the full report artifact (with images) |
For consistent CI environments (libvips, font antialiasing disabled), use the setup action:
- uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
with:
ruby-version: '4.0'
cache-apt-packages: trueThis installs Ruby, libvips (with apt caching), and disables font antialiasing for consistent rendering across CI runs.
| Input | Default | Description |
|---|---|---|
ruby-version |
(required) | Ruby version to install |
cache-apt-packages |
false |
Cache libvips apt packages for faster runs |
ruby-cache-version |
— | Bundler cache version key |
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v6
- uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
with:
ruby-version: '4.0'
cache-apt-packages: true
- run: bundle exec rake test
- uses: snap-diff/snap_diff-capybara/.github/actions/upload-screenshots@master
if: failure()
with:
name: screenshots
pr-comment: 'true'If you prefer full control, here's the expanded YAML:
Expand manual setup
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install libvips
run: sudo apt-get install -y libvips-dev
- name: Run tests
run: bundle exec rake test
- name: Upload screenshot report
if: failure()
uses: actions/upload-artifact@v7
with:
name: screenshot-report
path: doc/screenshots/snap_diff_report.html
archive: false
retention-days: 2
- name: Upload full report with images
if: failure()
uses: actions/upload-artifact@v7
with:
name: screenshot-report-full
path: doc/screenshots/
retention-days: 2When intentional UI changes are made, baselines need to be re-recorded. You can do this locally:
RECORD_SCREENSHOTS=1 bundle exec rake test
git add test/fixtures/screenshots/
git commit -m "chore: update screenshot baselines"Or add a workflow that maintainers can trigger manually:
Expand update-baselines workflow
# .github/workflows/update-baselines.yml
name: Update Screenshot Baselines
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to update baselines on'
required: true
default: 'main'
permissions:
contents: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.branch }}
- uses: snap-diff/snap_diff-capybara/.github/actions/setup-ruby-and-dependencies@master
with:
ruby-version: '4.0'
cache-apt-packages: true
- name: Record new baselines
run: RECORD_SCREENSHOTS=1 bundle exec rake test
continue-on-error: true
- name: Commit updated baselines
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add test/fixtures/ doc/screenshots/
git diff --staged --quiet || git commit -m "chore: update screenshot baselines"
git pushHow it works:
- Go to Actions → "Update Screenshot Baselines" → "Run workflow"
- Enter the branch name (e.g. your PR branch)
- The workflow records new baselines, commits, and pushes