The @cappa/plugin-storybook package bridges Storybook with Cappa’s screenshot pipeline. It fetches
stories from a running Storybook instance, opens each story in Playwright, and captures images using
the same comparison workflow as other targets. This guide walks through installing the plugin,
connecting it to Storybook, and fine-tuning how screenshots are generated.
Add the Storybook plugin alongside the Cappa core packages inside your project:
Terminal window
pnpmadd-D@cappa/plugin-storybook
Next, register the plugin inside cappa.config.ts so that the CLI knows how to discover stories. The
storybookUrl should point at the running Storybook server.
You can add additional plugin options to filter the stories that are captured:
includeStories – Optional predicate (story) => boolean. If provided, only stories for which it returns true are included. The argument is a StoryFilterContext with id, title, name, and filePath (the path "title/name", e.g. "Button/Primary").
excludeStories – Optional predicate (story) => boolean. If provided, stories for which it returns true are excluded (applied after includeStories).
defaultViewport – Override the default Playwright viewport when a story does not supply its
own settings.
You can use minimatch or regex inside your predicates for glob-like behavior:
The plugin ships with a Storybook addon that exposes story-level configuration to Cappa. Enable it by
adding @cappa/plugin-storybook to the Storybook addons list:
The addon registers a global decorator that collects parameters for each story. If you need to adjust
Storybook’s runtime when Cappa is in control, you can use the exported isCappa helper in
.storybook/preview.ts:
Start Storybook in one terminal and keep it running so the plugin can connect to the storybookUrl.
From another terminal, run the Cappa capture command from the directory that contains your config:
Terminal window
# Terminal 1
pnpmstorybook
# Terminal 2
pnpmcappacapture
Cappa will fetch the list of stories, load each one in Playwright, and write screenshots, diffs, and
reports to the configured output directory. Pair it with cappa review and cappa approve to follow
the normal approval workflow.
Keep in mind that the dev server of storybook might introduce delays in the story loading. It is therefore
recommended to build storybook before running cappa capture, and then run cappa on the resulting static files.
You can use start-server-and-test to start Storybook and Cappa in one command.
The id is used to identify the variant, and the label is used to display the variant in the report.
The options are mostly the same as the options for the story, but they are applied to the variant.
The filename is the name of the file that will be created for the variant. If not provided, it will be
generated from the story name and the variant id.