DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

How to Use BackstopJS with Storybook for Visual Regression Testing

Use Storybook canvas iframe URLs as BackstopJS scenarios, capture references at the viewports you care about, and approve only reviewed visual changes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To compare Storybook stories with BackstopJS, point BackstopJS scenarios at each story’s canvas iframe URL, capture reference screenshots, and run visual comparisons after changes. Review differences before approving them: a changed image is a prompt to inspect, not proof of a defect.

What BackstopJS checks in a Storybook workflow

BackstopJS automates visual regression checks by comparing screenshots over time. With Storybook, each scenario targets a particular rendered story, and each viewport produces a screenshot to compare with its saved reference.

As an Amazon Associate I earn from qualifying purchases.

This is different from a story test that checks whether a component renders or whether a play-function assertion passes. BackstopJS focuses on visual differences; teams may use it alongside functional tests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prepare stories and choose a stable Storybook URL

Make stories reproducible

Before capturing, make sure the story renders with the context it needs: theme or other providers, decorators, mocked data, fonts, and assets. Storybook preview configuration and decorators can provide context to stories; see Storybook setup documentation.

Use the canvas iframe, not the manager page

Open the story’s canvas in a new tab and use that URL as the scenario target. A common pattern is http://localhost:6006/iframe.html?id=<story-id>&viewMode=story. Replace <story-id> with the actual ID exposed by the Storybook project. Storybook documents its embedded canvas at the embed documentation; confirm the route and ID against the running project rather than assuming every version or build behaves identically.

Run BackstopJS against Storybook

1. Start the Storybook instance

For local development, the current Storybook install documentation uses npm run storybook to start the development server: Storybook install documentation. For repeatable CI runs, you can instead build and serve Storybook’s static output, as long as the server is reachable from the BackstopJS browser process.

2. Add a BackstopJS configuration

Define viewports and a scenario for every story state you want to capture. This minimal CommonJS configuration illustrates the pattern; it is not a tested project configuration, so verify the story ID and adapt the dimensions to your design system’s breakpoints.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
module.exports = {
  id: 'storybook-components',
  viewports: [
    { label: 'desktop', width: 1280, height: 800 },
    { label: 'mobile', width: 390, height: 844 }
  ],
  scenarios: [
    {
      label: 'Button / Primary',
      url: 'http://localhost:6006/iframe.html?id=components-button--primary&viewMode=story',
      selectors: ['document']
    }
  ]
};

The example uses one scenario and two viewports, so that scenario has a desktop and mobile capture. Add scenarios for other components, variants, or states. Keep labels descriptive so the comparison report is easy to review. BackstopJS supports JavaScript module configuration through --config; consult its README for configuration options such as selectors, waits, scripts, and viewport settings.

Do not expect Storybook to generate a complete BackstopJS configuration automatically. If you want scenario discovery, add project-specific code to create or maintain those entries.

3. Capture references, test, and review

  1. From the project environment where BackstopJS is installed, run backstop reference to capture the initial reference images.

    Rank #3
    Sale
    Web Design with HTML, CSS, JavaScript and jQuery Set
    • Brand: Wiley
    • Set of 2 Volumes
    • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
  2. After a visual change, run backstop test to compare new captures with the references.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Open the generated HTML/browser report and inspect each changed scenario and viewport. Decide whether the difference is an intended design update or a regression.

  4. Only for intended changes, run backstop approve. This promotes the latest test images into the reference collection.

These are the documented BackstopJS workflow commands; check the project’s installed version and README for any version-specific setup details.

Keep visual comparisons useful and repeatable

  • Control the inputs: keep browser, viewport, data, fonts, and asset-loading behavior steady between reference and test runs.
  • Wait for actual readiness: use BackstopJS readiness controls or scripts when the page needs time to settle, and base them on the application’s real loading conditions rather than an arbitrarily long delay.
  • Choose viewport coverage intentionally: more stories and viewport sizes mean more screenshots and can increase run time. Include the breakpoints or layouts your team needs to guard.
  • Make baselines deliberate: inspect the relevant story and viewport before approval; never treat approval as a way to silence an unexplained difference.
  • Consider environment consistency: BackstopJS lists Docker rendering as one option to reduce cross-platform rendering differences. It does not guarantee pixel-identical behavior in every environment.
  • Choose where Storybook runs: a local server is convenient during development; static or deployed Storybook can fit CI, provided the capture process can reach it reliably.

BackstopJS and Storybook Test Runner solve different problems

BackstopJS compares screenshots against visual references. Storybook Test Runner visits stories in a running Storybook instance and checks for rendering failures and play-function assertion failures, so it addresses related but distinct needs. Storybook’s current Test Runner page says, “Official support for Storybook Test Runner has ended,” and suggests Vite-based projects consider Storybook’s Vitest integration. Check support and compatibility for your exact Storybook version before adopting or retaining a runner.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common capture problems

The story URL does not load

Confirm the Storybook server is reachable from the BackstopJS process and that the story ID exists in the running build. Open the story’s canvas in a new tab and use that URL to check the route format, as described in Storybook’s embed documentation.

The capture looks different from the Storybook manager

Check that the preview has the same required decorators, providers, fonts, assets, and runtime setup as the intended story. The canvas iframe renders the preview rather than the surrounding manager interface.

Repeated captures vary unexpectedly

Stabilize browser and viewport settings, story data, and asset loading. If content loads asynchronously, configure a readiness condition or script that reflects the page’s real ready state instead of relying on a generic long delay.

A difference appears in the report

Inspect the actual pixels and determine whether the visual change is expected. If it is, update the references with backstop approve; that command uses the latest test batch, so approve only after reviewing it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your goal is to capture a rendered URL rather than maintain local browser-based baselines, ScreenshotNeo offers a screenshot API and MCP server. A single GET request returns an image or PDF; for an ordinary Storybook story URL, try:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=http://localhost:6006/iframe.html?id=components-button--primary&viewMode=story -o shot.webp

See the ScreenshotNeo API documentation for request options. A remote capture service cannot reach a Storybook server bound only to your own machine; make the target accessible to the service before using a local URL. ScreenshotNeo removes cookie banners, popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does BackstopJS discover Storybook stories automatically?

No complete automatic BackstopJS configuration is implied; define scenarios yourself or add project-specific discovery code.

Can BackstopJS replace functional story tests?

No. It compares screenshots; rendering and play-function assertions are a separate testing concern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.