Snapshots and layout checks
Fonts, styles and asset placement are checked two ways: compare the screen against a baseline image, or check where tagged elements sit relative to each other. Both measure in pt/dp, so they work on every screen size.
Both steps need the controller
The Mobile Controller must return scale in GET /devices/<id>/screen and serve GET /devices/<id>/elements (its API.md). With an older controller the steps fail and name the missing piece.
SNAPSHOT
SNAPSHOT: <name> [mask=<mask>[,<mask>…]] [tolerance=<percent>]
Baselines live in the case folder, one per screen class:
snapshots/
ios/375x667@2x/eula.png iPhone SE
ios/393x852@3x/eula.png iPhone 14 Pro / 15 Pro / 16
android/411x910@2.625x/eula.png moto g power
- Screen class = screen size in pt/dp plus the scale (pixels ÷ scale, scale printed with
%g). Phones with the same screen share a baseline; a test never names a device. - Images are stored at 1x — box-averaged from device pixels to pt/dp — which keeps files small and evens out anti-aliasing. Comparison happens at 1x.
- Comparison: a pixel differs when any channel differs by more than 24. The step fails when more than
tolerancepercent (default0.1) of unmasked pixels differ.
Masks
| Mask | Excludes |
|---|---|
status_bar | System status bar — iOS 20 pt on home-button phones, 59 pt on taller ones; Android 52 dp. |
nav_bar | Home indicator (34 pt, taller iPhones) or Android navigation bar (48 dp). |
tag:<testTag> | An element's bounds from the controller, e.g. a live temperature reading. |
rect:x,y,w,h | A rectangle in pt/dp. |
Outcomes
| Status | Step | When |
|---|---|---|
match | pass | Within tolerance. |
mismatch | fail | Too many pixels differ, or the baseline has a different size. |
missing | fail | No baseline for this screen class — the message lists the classes that have one. |
recorded | pass | Record mode: saved as a candidate, not compared. |
error | fail | Bad arguments, no scale from the controller, capture failed. |
Each step writes outputs/snapshots/<name>.actual.png and, when compared, <name>.baseline.png and <name>.diff.png (differing pixels red, masked areas blue, the rest dimmed). The run page shows all three under the step.
Re-baselining after a redesign
A new screen class or an intended change fails first. Then:
- On the run page, New baselines (N) downloads a zip of every
missing,mismatchandrecordedcapture, laid out asmt-tests/<case>/snapshots/<platform>/<class>/<name>.png(the case comes from the upload'scasefield; the build plugin passes the folder name). - Unzip into the app repo on a branch, check the images, commit. The viewer never writes to a repo.
Record mode (--record-snapshots, or Record snapshot baselines on the new-test page) saves every SNAPSHOT as a candidate without comparing: the run's status becomes recording and the run list shows Recording — a record run never counts as passed, and Build & Test never turns it on.
Ownership: a screen's baseline belongs to one case (in TemperatureSensor-App, eula owns the EULA and Home baselines). Other cases snapshot only the screens they're about, so one redesign means one re-baseline.
ASSERT_LAYOUT
Tags are Compose Modifier.testTag values. On Android the app must set testTagsAsResourceId = true on a root semantics node so uiautomator sees them; on iOS, Compose Multiplatform exposes them as the accessibility identifier. Tags must be unique on screen.
ASSERT_LAYOUT: eula_title centered-x
ASSERT_LAYOUT: eula_agree below eula_terms gap>=8
ASSERT_LAYOUT: eula_agree inside screen
SNAPSHOT: eula mask=status_bar
Checks: visible, inside screen/<tag2>, centered-x/-y, below/above/left-of/right-of (with gap>=N/gap<=N), no-overlap, aligned-left/-right/-top/-bottom/-center-x/-center-y. N is pt/dp or a percentage of screen width (x) / height (y) with a trailing %; default tolerance 2. A failure names the boxes it compared; a missing tag lists the tags on screen.