# Screenshots

> Send browser and mobile screenshots to VisualCI, with a baseline per platform and thresholds for anti-aliasing.

Source: https://visualci.com/docs/screenshots/
All of VisualCI's documentation: https://visualci.com/llms.txt

VisualCI compares PNG, JPEG and WebP images. Send the screenshots your tests already take, from Playwright, Capybara, Cypress, XCUITest or anything else:

```sh
visualci upload tmp/screenshots
```

Each file's path, relative to the directory you upload, without the extension, is its snapshot name. The CLI fingerprints each image by its pixels first, so an image VisualCI has already seen isn't uploaded or diffed again.

## Platforms

Screenshots of the same page differ between browsers, operating systems and devices. Give each its own baseline with a platform tag:

```sh
visualci upload --platform chrome-linux tmp/screenshots/chrome
visualci upload --platform ios-26.1/iphone-16 tmp/screenshots/ios
```

The platform is part of the baseline's key: `signup_form` on `chrome-linux` and `signup_form` on `ios-26.1/iphone-16` are compared separately.

Screenshots are taken on the machine that runs the tests, so a laptop's screenshots won't match CI's pixel for pixel. Compare screenshots from CI with each other.

## Thresholds

By default every pixel must match. Browsers draw text and edges with anti-aliasing that varies slightly between runs, so browser screenshots usually need a threshold:

```sh
visualci upload --threshold 0.1 tmp/screenshots
```

The threshold is the colour difference (0 to 1) below which two pixels count as the same, as in pixelmatch; 0.1 is pixelmatch's default. The project's **Settings** tab has a project-wide threshold, and a setting that skips pixels that look like anti-aliasing (with a threshold above 0).

## Ruby and RSpec

The `visualci` gem queues snapshots during an RSpec run and uploads them with the CLI when the run ends:

```ruby
# Gemfile
gem 'visualci', group: :test
```

```ruby
# spec_helper.rb
require 'visualci/rspec'
RSpec.configure { |c| c.include VisualCI::RSpec }

# in a spec
expect_image_to_match_visual('signup_form/dark/1280', screenshot_path, threshold: 0.1)
expect_pdf_to_match_visual('invoice_typical', pdf_path)
expect_json_to_match_snapshot('api/users/show', JSON.parse(response.body))
expect_html_to_match_snapshot('emails/welcome', mail.html_part.body.to_s)
expect_text_to_match_snapshot('reports/monthly', report.to_s)
```

The helpers don't fail the example. Changes are reviewed on VisualCI, where the GitHub check waits; a project in `strict` mode fails the CI step instead, with `visualci build finalize --wait`.

They're on when `VISUALCI_TOKEN` is set (and `VISUALCI_DISABLED` isn't). The build comes from `VISUALCI_BUILD_ID`. In CI, create the build once before the shards run:

```sh
export VISUALCI_BUILD_ID=$(visualci build create --shards "$CIRCLE_NODE_TOTAL")
bundle exec rspec    # each shard uploads and finalizes its own snapshots at exit
```

Each shard finalizes the shard named by `VISUALCI_SHARD`, or `CIRCLE_NODE_INDEX`. Without `VISUALCI_BUILD_ID`, the helpers create a local build, which can be viewed but not approved.
