Set Up With an AI Assistant
This page is written for AI coding assistants. It tells an assistant how to add Get Snappy visual regression testing to the project it is working in: which files to change, what to ask the user for, and how to check it worked.
To use it, ask your assistant something like:
Set up Get Snappy in this project. Follow https://docs.get-snappy.com/guide/agent-setup.md
The rest of the page is addressed to the assistant.
How Get Snappy works
Read this first so the later steps make sense.
- The project's tests call
snap(...)at the points to capture.snapsends the page's HTML to a local server. It does not take a screenshot itself, and it does nothing unless snapshots are enabled. - In CI, the
get-snappyCLI runs the test suite withget-snappy snapshot-run. It starts the local server, runs the command intest_command, renders each HTML snapshot in Playwright browsers, and uploads the screenshots. - Get Snappy compares each screenshot with the approved baseline and reports the result as a GitHub check on the commit. People review the differences in the Get Snappy web app.
- Builds on the project's auto-approve branch (usually
main) are approved automatically. They become the baselines that branch builds are compared against.
Supported stacks:
Rules
- Detect the stack before changing anything. If
mix.exsdepends onphoenix, use the Phoenix steps. Ifpackage.jsondepends onember-source, use the Ember steps. If neither matches, stop and tell the user Get Snappy does not support this project yet. - Never write the API key into a file in the repository. It belongs in the CI provider's secret store. Refer to it only as the
GET_SNAPPY_API_KEYenvironment variable. - Do not invent values you can't find. If you can't determine the CI provider, the asset directory or the test command, ask the user.
- Keep the existing test suite working locally. Snapshots must be off unless explicitly enabled, so
mix testorember teston a developer machine behaves exactly as before. - Start small. Add snapshots to a handful of important pages (3 to 10), not every test. The user can add more once the first build works.
Step 1: Things only the user can do
These steps need a browser and an account, so you can't do them. Give the user this checklist and wait for them to confirm before Step 5. You can do Steps 2 to 4 while they work through it.
- Install the Get Snappy GitHub App for the repository: https://github.com/apps/get-snappy
- Create a project at https://get-snappy.com/admin/projects, linked to this repository. Set Auto Approve Branch to the branch pull requests merge into (usually
main). - Copy the project's API key and save it as a CI secret named
GET_SNAPPY_API_KEY. For GitHub Actions: Settings → Secrets and variables → Actions → New repository secret.
Step 2: Add the library
Phoenix
Add the dependency to mix.exs, then run mix deps.get:
Add this to config/test.exs:
- Replace
MyAppWeb.Layoutswith the module that defines the app's root layout. Find it by searching forroot.html.heexor for:rootin the router'sput_root_layoutplug. layoutwraps fragments fromrender(view)andrender_component(...)in the root layout, so they're captured with the app's CSS. Full pages fromlive(...)are sent as they are.- If the root layout reads assigns other than
page_titleandflash, list them with nil or test values. Otherwise rendering fails with a missing-assign error. For example:layout_assigns: %{current_scope: nil}. <script>tags are removed before rendering, so JavaScript never runs in snapshots.- If the project already has a
wrapper_fnin itsex_snappyconfig, it was set up on an older version.layoutreplaces it, and takes precedence when both are set.
Ember
Use the project's package manager (npm install -D or yarn add -D) if it doesn't use pnpm.
Step 3: Add snapshots to tests
Phoenix
Add import ExSnappy to the test module, then call snap after the page has reached the state to capture:
snap accepts the html from live(...), a LiveView (snap(view) renders it), the result of render(view), or the output of render_component(...).
Ember
Call snap in acceptance or rendering tests after the page has settled:
snap(assert) names the snapshot after the test module and test name. Pass a string instead for a custom name: await snap('product-list-filtered').
Naming
Snapshot names must be unique within a build, because they're used to match each screenshot with its baseline.
- Phoenix: the name comes from the test name. If a test calls
snapmore than once, give every call after the first aname:option, as in the example above. - Ember: if a test snaps more than once, pass a distinct name to each call after the first.
Never generate names from data that changes between runs, such as IDs, timestamps or random values.
Options
Phoenix options go in the second argument to snap:
dimensions: viewport sizes to capture. Each size is a separate screenshot. Defaults to 1920×1080.playwright_options.full_page: capture the whole scrollable page. Defaults totrue, and can be set for all snapshots withconfig :ex_snappy, full_page: false.playwright_options.locator: a CSS selector that matches exactly one element, to capture only that element.playwright_options.dark_mode: render withprefers-color-scheme: dark.playwright_options.mask: CSS selectors to cover with a solid box. Use this for content that changes between runs.layout: falseorlayout_assigns: %{...}: override the layout settings for one snapshot.
Ember options go in the second argument: scope (a CSS selector to capture) and dimensions (a list of { width, height }).
Keep snapshots deterministic
Anything that changes between runs shows up as a visual difference on every build. Before adding a snapshot, check the page for:
- Current dates, times or relative times ("3 minutes ago"). Use fixed values in test data, or mask the element.
- Random or sequence-generated data shown on the page, such as IDs or generated names. Use fixed fixture values.
- Content loaded asynchronously. In LiveView, call
render_async(view)before snapping. - Images or fonts loaded from external URLs. They may not load reliably in CI.
Step 4: Add .get-snappy.yml
Create .get-snappy.yml in the directory CI runs get-snappy from (usually the repository root).
Phoenix:
Ember:
For Ember, test_command must test the already-built dist directory, so CI has to build the app before running get-snappy.
Step 5: Run it in CI
Find the CI configuration (for example .github/workflows/*.yml, .buildkite/, .circleci/config.yml or .gitlab-ci.yml) and change the job that runs the tests.
Requirements
-
Playwright 1.65.2 and its browsers.
get-snappy0.7.2 runs Playwright 1.65.2 and launches that version's browsers, so the job must run inmcr.microsoft.com/playwright:v1.65.2-noble, or an image built from it. The image already has the browsers, their system dependencies and Node.js. If the job already uses a custom image, build it from the Playwright image and add the project's language toolchain. Outside that image, runget-snappy install-browsersafter installing the CLI. -
The
get-snappyCLI. It is the@get-snappy/clipackage on npm and needs Node.js 22.12 or later. Pin the version:When upgrading, use the Playwright image version the new release lists in the package's
CHANGELOG.md(on npm, under the Code tab). -
Built assets. Build them before running
get-snappy. For Phoenix, runmix assets.build(or the project's equivalent). For Ember, build todist. -
Environment variables:
-
Replace the test step. Run
get-snappy snapshot-runinstead of the test command, not as well as it. It runstest_commanditself and exits with a non-zero status if the tests fail.
GitHub Actions example
Adapt the existing workflow rather than copying this whole file. The parts that matter are the container, the environment variables and the last two steps.
On pull_request events, github.sha is a temporary merge commit. Use github.event.pull_request.head.sha so the build is recorded against the commit the developer pushed, which is the one they'll look it up by.
Other CI providers
Set the same variables from the provider's built-in values. For Buildkite: GET_SNAPPY_COMMIT: $BUILDKITE_COMMIT and GET_SNAPPY_BRANCH: $BUILDKITE_BRANCH.
Tests split across parallel jobs
If the suite is split across several CI jobs (for example with ember-exam partitions), every job is part of one build:
- In every job, set
GET_SNAPPY_PARALLEL=trueandGET_SNAPPY_UNIQUE_IDENTIFIERto a value that is the same across the jobs but unique to this run. A commit SHA is not enough, because a commit can be built more than once. Combine the CI run ID with the attempt number: on Buildkite$BUILDKITE_BUILD_ID$BUILDKITE_RETRY_COUNT, on GitHub Actions${{ github.run_id }}-${{ github.run_attempt }}. - Add one job that runs after all the test jobs and runs
get-snappy finalize-buildwith the same environment variables.
Step 6: Check it worked
- Show the user the changes, then commit them on a branch and push, if the user agrees.
- Wait for CI. In the log of the test step,
get-snappyprintsUsing config file: .../.get-snappy.ymlwhen it finds the config. If that line is missing, the file is in the wrong directory. - Check the build:
- If the Get Snappy MCP server is connected (see AI Assistants (MCP)), call
find_buildswith the commit SHA, thenget_buildon the result. - Otherwise, ask the user to open the project in Get Snappy.
- If the Get Snappy MCP server is connected (see AI Assistants (MCP)), call
What to expect: there are no baselines until a build runs on the auto-approve branch, so every screenshot in the first branch build is reported as new. Once the setup is merged and the auto-approve branch has built, later branch builds are compared against it.
Troubleshooting
- No build appears. Check the CI log for errors from
get-snappy. IfGET_SNAPPY_API_KEY,GET_SNAPPY_COMMITorGET_SNAPPY_BRANCHis missing or wrong, the build can't be created andget-snappyexits with an error. More detail is written toget-snappy.login the working directory. Print that file in CI when the step fails. - Build has zero snapshots. For Phoenix, check
EX_SNAPPY_ENABLED=trueis set on the step that runsget-snappy. Also check that the tests callingsnapran and weren't excluded by tags. - Screenshots have no styling. The assets weren't built before
get-snappyran, orlocal_dist_dirpoints at the wrong directory. For Phoenix fragments, also check thelayoutconfig. - Error rendering the layout (Phoenix). The root layout reads an assign that isn't provided. Add it to
layout_assigns. - Duplicate or overwritten snapshots. Two
snapcalls share a name. Give each call in a test a distinctname:. - Differences on every build for the same page. Something on the page changes between runs. See Keep snapshots deterministic.
More detail
- Elixir Phoenix guide and ExSnappy docs on HexDocs
- Ember.js guide
- Installing the get-snappy CLI
- AI Assistants (MCP): let the assistant read build results while it works