Storybook Test Runner visual testing quickstart
Set up visual testing in Storybook with Test Runner and the Argos CLI.
To add visual testing with Storybook Test Runner, install @argos-ci/storybook and @argos-ci/cli, call argosScreenshot(page, context) in the postVisit hook of .storybook/test-runner.ts, run test-storybook against your built Storybook, and upload the screenshots with npm exec -- argos upload ./screenshots in CI with the ARGOS_TOKEN environment variable set.
What Argos adds
A screenshot of every story. The
postVisithook captures each story after Test Runner has rendered it and run itsplayfunction.Baselines from your Git history. Argos picks the baseline build automatically, so there are no images to commit.
Review on the pull request. Visual changes become a pull request check that your team approves or rejects.
Prerequisites
Node.js 22 or later
Storybook v8+ set up in your project
Install
Install the Argos CLI, the Argos Storybook SDK, and Storybook Test Runner:
npm i --save-dev @argos-ci/cli @argos-ci/storybook @storybook/test-runneryarn add --dev @argos-ci/cli @argos-ci/storybook @storybook/test-runnerpnpm add --save-dev @argos-ci/cli @argos-ci/storybook @storybook/test-runnerbun add --dev @argos-ci/cli @argos-ci/storybook @storybook/test-runnerCapture screenshots
Add a .storybook/test-runner.ts file to your project. The postVisit hook captures a screenshot of every story:
import type { TestRunnerConfig } from "@storybook/test-runner";
import { argosScreenshot } from "@argos-ci/storybook/test-runner";
const config: TestRunnerConfig = {
async postVisit(page, context) {
await argosScreenshot(page, context);
},
};
export default config;Screenshots are written to the ./screenshots directory. Add ./screenshots to your .gitignore file to avoid committing them.
Set up CI
Add a workflow that builds your Storybook, runs the tests, and uploads the screenshots to Argos. If you use another CI provider, adapt the steps with Run Argos in CI:
name: Argos
on:
pull_request:
push:
branches:
- main
jobs:
argos:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Build Storybook
run: npm run build-storybook
- name: Install Playwright dependencies
run: npx playwright install --with-deps chromium
- name: Run Storybook tests and capture screenshots
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server ./storybook-static --port 6006 --silent" \
"npx wait-on tcp:127.0.0.1:6006 && npm run test-storybook"
- name: Upload screenshots to Argos
run: npm exec -- argos upload ./screenshots
env:
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}ARGOS_TOKEN is the project token from Settings → Authentication → Project token. On GitHub Actions, you can also use OIDC or tokenless authentication to avoid managing a secret.
To learn how to run tests on a deployed Storybook, refer to the Storybook Test Runner documentation.
You're all set
Push your changes and open a pull request — the Argos check appears on it once the build is uploaded. Review the visual changes, approve or reject them, and merge with confidence.
Frequently asked questions
Next steps
Stabilize screenshots – Prevent flaky diffs before they reach your pull requests
Storybook SDK reference – All options and helpers
Storybook + Test Runner example – A complete working setup
Need help? Join our Discord, open an issue on GitHub, or send us an email.
Last updated
Was this helpful?