For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/agent-setup.md.

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.

  1. The project's tests call snap(...) at the points to capture. snap sends the page's HTML to a local server. It does not take a screenshot itself, and it does nothing unless snapshots are enabled.
  2. In CI, the get-snappy CLI runs the test suite with get-snappy snapshot-run. It starts the local server, runs the command in test_command, renders each HTML snapshot in Playwright browsers, and uploads the screenshots.
  3. 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.
  4. 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:

StackLibrary
Elixir Phoenix and Phoenix LiveViewex_snappy (Hex)
Ember.js@get-snappy/snappy-ember-client (npm)

Rules

  • Detect the stack before changing anything. If mix.exs depends on phoenix, use the Phoenix steps. If package.json depends on ember-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_KEY environment 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 test or ember test on 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.

  1. Install the Get Snappy GitHub App for the repository: https://github.com/apps/get-snappy
  2. 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).
  3. 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:

{:ex_snappy, "~> 0.6.3", only: :test}

Add this to config/test.exs:

config :ex_snappy,
  enabled: System.get_env("EX_SNAPPY_ENABLED") == "true",
  layout: {MyAppWeb.Layouts, :root}
  • Replace MyAppWeb.Layouts with the module that defines the app's root layout. Find it by searching for root.html.heex or for :root in the router's put_root_layout plug.
  • layout wraps fragments from render(view) and render_component(...) in the root layout, so they're captured with the app's CSS. Full pages from live(...) are sent as they are.
  • If the root layout reads assigns other than page_title and flash, 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_fn in its ex_snappy config, it was set up on an older version. layout replaces it, and takes precedence when both are set.

Ember

pnpm add -D @get-snappy/snappy-ember-client

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:

defmodule MyAppWeb.ProductLiveTest do
  use MyAppWeb.ConnCase, async: true
  import Phoenix.LiveViewTest
  import ExSnappy

  test "lists products", %{conn: conn} do
    {:ok, view, html} = live(conn, ~p"/products")
    assert html =~ "Products"

    snap(html)

    view |> element("button", "Filter") |> render_click()
    snap(view, name: "filtered")
  end
end

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:

import { snap } from '@get-snappy/snappy-ember-client';

test('product list', async function (assert) {
  await visit('/products');
  await snap(assert);
});

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 snap more than once, give every call after the first a name: 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:

snap(html,
  name: "dark",
  dimensions: [%{width: 1280, height: 800}, %{width: 375, height: 667}],
  playwright_options: %{dark_mode: true, mask: [".timestamp"]}
)
  • 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 to true, and can be set for all snapshots with config :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 with prefers-color-scheme: dark.
  • playwright_options.mask: CSS selectors to cover with a solid box. Use this for content that changes between runs.
  • layout: false or layout_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:

local_dist_dir: "priv/static"
test_command: "mix test"
browsers: ["chrome"]
snappy_workers: 4

Ember:

local_dist_dir: "dist"
test_command: "pnpm ember test --path=dist"
browsers: ["chrome"]
snappy_workers: 4
KeyMeaning
local_dist_dirDirectory holding the built static assets (CSS, images, fonts). Snapshots are rendered with these, so the assets must be built before get-snappy runs.
test_commandShell command that runs the test suite. If the project's CI already uses a script to run tests, use that.
browsersAny of chrome, firefox and webkit. Start with ["chrome"]. Each extra browser multiplies the number of screenshots.
snappy_workersBrowser instances per browser. Defaults to 4. Lower it on small CI machines.

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

  1. Playwright 1.65.2 and its browsers. get-snappy 0.7.2 runs Playwright 1.65.2 and launches that version's browsers, so the job must run in mcr.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, run get-snappy install-browsers after installing the CLI.

  2. The get-snappy CLI. It is the @get-snappy/cli package on npm and needs Node.js 22.12 or later. Pin the version:

    npm install -g @get-snappy/cli@0.7.2

    When upgrading, use the Playwright image version the new release lists in the package's CHANGELOG.md (on npm, under the Code tab).

  3. Built assets. Build them before running get-snappy. For Phoenix, run mix assets.build (or the project's equivalent). For Ember, build to dist.

  4. Environment variables:

    VariableValue
    GET_SNAPPY_API_KEYThe CI secret from Step 1. Required.
    GET_SNAPPY_COMMITFull SHA of the commit being tested. Required.
    GET_SNAPPY_BRANCHName of the branch being tested. Required.
    EX_SNAPPY_ENABLEDtrue. Phoenix only, to turn snap on.
  5. Replace the test step. Run get-snappy snapshot-run instead of the test command, not as well as it. It runs test_command itself 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.

jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/playwright:v1.65.2-noble # or the project's image built from it
    env:
      GET_SNAPPY_API_KEY: ${{ secrets.GET_SNAPPY_API_KEY }}
      GET_SNAPPY_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
      GET_SNAPPY_BRANCH: ${{ github.head_ref || github.ref_name }}
      EX_SNAPPY_ENABLED: "true"
    steps:
      - uses: actions/checkout@v4
      # ...the project's existing setup, dependency and asset build steps...
      - name: Install get-snappy
        run: npm install -g @get-snappy/cli@0.7.2
      - name: Run tests with snapshots
        run: get-snappy snapshot-run

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:

  1. In every job, set GET_SNAPPY_PARALLEL=true and GET_SNAPPY_UNIQUE_IDENTIFIER to 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 }}.
  2. Add one job that runs after all the test jobs and runs get-snappy finalize-build with the same environment variables.

Step 6: Check it worked

  1. Show the user the changes, then commit them on a branch and push, if the user agrees.
  2. Wait for CI. In the log of the test step, get-snappy prints Using config file: .../.get-snappy.yml when it finds the config. If that line is missing, the file is in the wrong directory.
  3. Check the build:
    • If the Get Snappy MCP server is connected (see AI Assistants (MCP)), call find_builds with the commit SHA, then get_build on the result.
    • Otherwise, ask the user to open the project in Get Snappy.

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. If GET_SNAPPY_API_KEY, GET_SNAPPY_COMMIT or GET_SNAPPY_BRANCH is missing or wrong, the build can't be created and get-snappy exits with an error. More detail is written to get-snappy.log in the working directory. Print that file in CI when the step fails.
  • Build has zero snapshots. For Phoenix, check EX_SNAPPY_ENABLED=true is set on the step that runs get-snappy. Also check that the tests calling snap ran and weren't excluded by tags.
  • Screenshots have no styling. The assets weren't built before get-snappy ran, or local_dist_dir points at the wrong directory. For Phoenix fragments, also check the layout config.
  • 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 snap calls share a name. Give each call in a test a distinct name:.
  • Differences on every build for the same page. Something on the page changes between runs. See Keep snapshots deterministic.

More detail