screenshot-tests

$npx mdskill add stripe/stripe-android/screenshot-tests

Writes Paparazzi screenshot tests

  • Solves UI testing challenges
  • Depends on Paparazzi and Gradle
  • Decides using test class structure
  • Delivers test results via Gradle

SKILL.md

.github/skills/screenshot-testsView on GitHub ↗
---
name: screenshot-tests
description: Use when writing or running Paparazzi screenshot tests in stripe-android — covers PaparazziRule setup, recording/verifying commands, and test structure
---

# Screenshot Tests (Paparazzi)

We use [Paparazzi](https://github.com/cashapp/paparazzi) for screenshot testing via the `screenshot-testing` module.

## Recording Screenshots

Record (update) screenshots after UI changes:

```bash
./gradlew :<module>:recordPaparazziDebug
```

To record a specific test class only:

```bash
./gradlew :<module>:recordPaparazziDebug --tests "com.stripe.android.package.MyScreenshotTest"
```

Wildcard form also works:

```bash
./gradlew :<module>:recordPaparazziDebug --tests "*.MyScreenshotTest"
```

New or updated screenshots are written to `<module>/src/test/snapshots/images/` and added to the Git staging area.

## Verifying Screenshots

Verify screenshots match recorded baselines (used on CI):

```bash
./gradlew :<module>:verifyPaparazziDebug
```

Failure diffs are written to `<module>/out/failures` (git-ignored).

## Test Class Structure

```kotlin
internal class MyScreenshotTest {

    @get:Rule
    val paparazziRule = PaparazziRule(
        SystemAppearance.entries,        // Light/Dark
        PaymentSheetAppearance.entries,  // Default/Custom/Crazy appearances
        FontSize.entries,                // Default/Large font
        boxModifier = Modifier.padding(horizontal = 16.dp),
    )

    @Test
    fun testDefault() {
        paparazziRule.snapshot {
            MyComposable(/* ... */)
        }
    }
}
```

- `PaparazziRule` generates all permutations of the config options automatically.
- Each test produces one snapshot per permutation (e.g., 12 images for 2 themes x 3 appearances x 2 font sizes).
- Snapshots are named `<package>_<class>_<method>[<permutation>].png`.

## Available Config Options

| Option | Values | Import |
|--------|--------|--------|
| `SystemAppearance` | `LightTheme`, `DarkTheme` | `com.stripe.android.screenshottesting` |
| `FontSize` | `DefaultFont`, `LargeFont` | `com.stripe.android.screenshottesting` |
| `PaymentSheetAppearance` | `DefaultAppearance`, `CustomAppearance`, `CrazyAppearance` | `com.stripe.android.utils.screenshots` |

## Common Mistakes

- **Using `-Precord` or other flags** — Paparazzi uses a separate `recordPaparazziDebug` task, not a project property.
- **Running `testDebugUnitTest` to record** — this only _verifies_ against existing snapshots; use `recordPaparazziDebug` to update them.
- **Forgetting to commit updated snapshots** — recorded images go into `src/test/snapshots/images/` and must be committed.

More from stripe/stripe-android

SkillDescription
compose-testsUse when writing Compose UI tests in stripe-android — covers composeRule setup, Robolectric annotations, node assertions, and test tag patterns
delegate-low-reasoning-workUse when running routine Gradle tests, builds, lint, formatting, generated-output checks, or verbose output collection in stripe-android. Delegate independent low-judgment work to a low-cost subagent to preserve the main context.
fixing-flakesReproduce, diagnose, and fix flaky stripe-android tests with focused, repeated validation and evidence-driven synchronization or determinism fixes. Use for intermittent unit, coroutine, Robolectric, Compose, screenshot, instrumentation, Gradle Managed Device, PaymentSheet E2E, Chrome, WebView, UiAutomator, or Espresso failures, while ensuring temporary ShampooRule edits never enter commits or pull requests.
network-testsUse when writing NetworkRule integration tests in stripe-android — covers testBodyFromFile, inline JSON modification, request matchers, and fixture patterns
parameterized-testsUse when writing, converting, or reviewing parameterized JVM, Robolectric, instrumentation, or Paparazzi tests in stripe-android. Covers TestParameterInjector runners, source-set dependencies, method versus class parameters, value providers, case matrices, and stable test names.
write-unit-testsUse when writing or structuring unit tests or fake test implementations in stripe-android — covers scenarios, Turbine interaction tracking and Flow testing, and Truth assertions