Tutorial
Screenshot testing with GitHub Actions

Visual regression testing catches UI bugs that unit tests miss. But setting up Puppeteer or Playwright in CI is painful — browser binaries, memory limits, and flaky headless rendering. The Allscreenshots API lets you skip all of that.
What you'll build
A GitHub Actions workflow that captures screenshots of your preview deployment on every pull request and uploads them as artifacts for visual review.
Prerequisites
- A GitHub repository with a preview deployment setup (Vercel, Netlify, or similar)
- An Allscreenshots account with an API key
Step 1: Store your API key
Add your Allscreenshots API key as a GitHub repository secret:
- Go to your repo Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
SCREENSHOT_API_KEY - Value: your API key from the Allscreenshots dashboard
Step 2: Create the workflow file
Create .github/workflows/screenshots.yml:
name: Visual Regression Tests
on:
pull_request:
branches: [main]
jobs:
screenshots:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait for preview deployment
uses: patrickedqvist/wait-for-vercel-[email protected]
id: preview
with:
token: ${{ secrets.GITHUB_TOKEN }}
max_timeout: 300
- name: Capture homepage
run: |
curl -s -X POST 'https://api.allscreenshots.com/v1/screenshots' \
-H 'X-API-Key: ${{ secrets.SCREENSHOT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"url": "${{ steps.preview.outputs.url }}",
"fullPage": true,
"viewport": { "width": 1920, "height": 1080 }
}' -o homepage.png
- name: Capture mobile view
run: |
curl -s -X POST 'https://api.allscreenshots.com/v1/screenshots' \
-H 'X-API-Key: ${{ secrets.SCREENSHOT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"url": "${{ steps.preview.outputs.url }}",
"fullPage": true,
"viewport": { "width": 375, "height": 812 }
}' -o mobile.png
- name: Upload screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots-pr-${{ github.event.number }}
path: |
homepage.png
mobile.png
retention-days: 30This workflow waits for your Vercel preview deployment, captures both desktop and mobile screenshots, and uploads them as artifacts.
Step 3: Capture multiple pages
For larger sites, capture multiple pages using a matrix strategy:
jobs:
screenshots:
runs-on: ubuntu-latest
strategy:
matrix:
page: ['/', '/pricing', '/about', '/docs']
steps:
- name: Capture ${{ matrix.page }}
run: |
SAFE_NAME=$(echo "${{ matrix.page }}" | sed 's/\//-/g' | sed 's/^-//')
curl -s -X POST 'https://api.allscreenshots.com/v1/screenshots' \
-H 'X-API-Key: ${{ secrets.SCREENSHOT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d "{
\"url\": \"${{ steps.preview.outputs.url }}${{ matrix.page }}\",
\"fullPage\": true,
\"viewport\": { \"width\": 1920, \"height\": 1080 }
}" -o "${SAFE_NAME:-homepage}.png"
- uses: actions/upload-artifact@v4
with:
name: screenshot-${{ matrix.page }}
path: '*.png'Step 4: Add screenshot comparison
For automated comparison against baselines, add a step that downloads the previous screenshot from the main branch and diffs them:
- name: Download baseline
uses: dawidd6/action-download-artifact@v6
with:
name: screenshots-baseline
branch: main
workflow: screenshots.yml
if_no_artifact_found: warn
- name: Compare screenshots
run: |
if [ -f baseline-homepage.png ]; then
# Use ImageMagick to compare
compare -metric AE homepage.png baseline-homepage.png diff.png 2>&1 || true
echo "Pixel difference: $(compare -metric AE homepage.png baseline-homepage.png null: 2>&1)"
fiTips
No preview deployment?
If your project doesn't have preview deployments, you can capture screenshots of your staging URL instead:
- name: Capture staging
run: |
curl -s -X POST 'https://api.allscreenshots.com/v1/screenshots' \
-H 'X-API-Key: ${{ secrets.SCREENSHOT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{ "url": "https://staging.yourapp.com", "fullPage": true }' \
-o screenshot.pngPost screenshots to PR comments
Add a step to post screenshots as PR comments using the GitHub API:
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: screenshots
message: |
## Visual Preview
Screenshots captured from preview deployment.
Download: ${{ steps.upload.outputs.artifact-url }}Speed
The API call typically takes 2-5 seconds per screenshot. Capturing 10 pages adds about a minute to your pipeline — far less than running Playwright locally.
Wrapping up
With GitHub Actions and Allscreenshots, you get visual regression testing without managing browser infrastructure in CI. The API handles rendering, and GitHub Actions handles the workflow.
For the full setup guide, see the GitHub Actions integration page.
Find out how easy it is to capture and share pixel-perfect screenshots at scale using Allscreenshots. Sign up for a free account and start integrating your first screenshot API call today.


