Skip to main content
A SwiftUI view can compile clean and still clip at a larger text size or lose its contrast in the dark appearance. A snapshot in a check’s expect compares the screen the check ends on to a baseline image, with no model.

Add a snapshot to a check

Add these keys to an existing check file:
Run the checks:
A missing baseline is recorded and ends needs_review. Inspect the image before you commit it. Later runs compare against that baseline. Baselines are PNGs in .mobster/snapshots/<check>/<name>@<device>-<appearance>-<content_size>-<locale>.png, for example .mobster/snapshots/settings/settings@iphone-17-pro-dark-accessibility-extra-large-default.png. A condition the check doesn’t set reads default. <check> is the check file’s path under .mobster/checks, without the suffix. Commit them: they are the expected screens.

Read a changed snapshot

  • No baseline for this device and these conditions. Mobster saves the screen as the baseline and the check ends needs_review with “baseline recorded”. It never fails a check for a missing baseline. Look at the PNG, commit it, and the next run compares to it.
  • A baseline. Mobster takes a full-size PNG after the screen settles and compares it to the baseline.
  • The same size, within the threshold. The snapshot passes.
  • Over the threshold. The check fails with class finding, the message says how much of the screen changed, and the run folder holds snapshots/<name>-diff.png: the screen faded, with the changed pixels red.
  • A different size. The check fails and says both sizes. A baseline belongs to one device, so another device gets its own baseline.
  • --update-snapshots. Mobster writes the baseline whatever the screen shows, and the snapshot passes. With --check NAME it updates only the checks with that name or file name. Read the diff of the PNGs in your pull request before you commit.
Mobster blurs both images by 2 px, then counts a pixel as changed when any color channel differs by more than 24 of 255. Antialiasing and subpixel text rendering stay under that, so they never fail a check. The check fails when more than threshold percent of the unmasked pixels changed (default 0.1). Mobster leaves out:
  • Your masks. An id or label mask covers every shown element it matches. A rect is in points. Masked pixels count in neither the changed pixels nor the total.
  • The keyboard. While the keyboard shows, Mobster masks it and the text fields on screen, because a caret blinks.
  • The status bar. On a simulator, Mobster sets 9:41, full battery, full signal and Wi-Fi for the run (a status_bar condition of yours wins) and puts it back afterwards. On a real iPhone it can’t, so it masks the status bar.
A person reads the diff and decides whether a change is a bug. Mobster doesn’t compare one baseline across two devices or check contrast ratios. A baseline file names the device but not the iOS version, so update the baselines when you move to a new simulator runtime.

Accept an intended change

After you inspect the diff, update only the check whose screen you meant to change. For a check named settings:
This replaces its baselines with the screens from this run. Review the PNG changes before you commit them.

Clean up old baselines

mobster test snapshots marks each baseline current, stale (its check still has the snapshot, but not for this appearance, text size or locale) or orphaned (no check has that snapshot). Mobster lists them and deletes nothing: remove them with git rm. In results.json, a result with a snapshot has snapshot with name, status (matched, changed, size_changed, recorded or updated), changedPercent, thresholdPercent, regions and masks as [x, y, width, height] in pixels, size, diffMs, and the absolute paths of the baseline, current and diff images. junit.xml lists the same paths in the case’s <system-out>, so a CI system can attach the diff. The run’s own report shows the three images side by side.