<!-- KeepSnappy docs for keepsnappy CLI 0.1.0-alpha.35 -->

# e2e

> What changes for your e2e tests when you add KeepSnappy, and why runs with AI steps don't count.

e2e (formerly TesterArmy e2e) is an open test runner, the `e2e` package ([e2e.com](https://e2e.com/docs/mobile)). This page is for teams whose end-to-end tests use it. Its tests are TypeScript files with locators and `expect`. This page covers only what is different with e2e. [Getting started](https://keepsnappy.com/docs/getting-started.md) has the rest of the setup.

The examples use iOS, on a simulator in GitHub Actions. For Android, or for real phones on BrowserStack, see [Other setups](#other-setups).

KeepSnappy wraps your `e2e run` command and measures the app while the tests run. It measures only tests that use no AI: locators, taps, typing and `expect`. A run that used AI doesn't count. You can keep AI tests in the same project, under a tag that the measured command leaves out.

## Install

Add e2e's two packages at exact versions, and commit the lock file:

```json
{
  "devDependencies": {
    "e2e": "0.22.0",
    "@e2e-dev/mobile": "0.12.5"
  }
}
```

If the tests live in a separate package, create its `package.json` before installing. Use that package's package manager and commit its lockfile. Without the manifest, npm can pick up the app's package-manager and Node.js requirements from a parent directory.

Both packages change often before version 1.0. KeepSnappy reads the report format `report-1` and refuses any other. It does not check package versions.

KeepSnappy has been tried with `e2e` 0.18.0 to 0.22.0 and `@e2e-dev/mobile` 0.10.0 to 0.12.5. The pair above is the newest of them. Outside that range, check that a run counts before you trust the session.

e2e needs Node.js 22.22.3 or a later 22.x, or Node.js 24.8 or newer. The CI example uses Node 24.

The config and a test, as in e2e's own [mobile guide](https://e2e.com/docs/mobile). They open the app that your CI job installed, by its bundle id:

```js
// e2e.config.ts
import { mobile } from '@e2e-dev/mobile';

export default {
  targets: [{ name: 'ios', engine: mobile({ platform: 'ios' }), app: { bundleId: 'com.example.app' } }],
  workers: 1,
};
```

```js
// tests/greeting.e2e.ts
import { expect, test } from 'e2e';

test('greets the name you type', async ({ app, screen }) => {
  await app.open();
  await screen.getByTestId('name').fill('Ada');
  await screen.getByTestId('greet').tap();
  await expect(screen.getByTestId('greeting')).toHaveText('Hello, Ada!');
});
```

## Settings in keepsnappy.yml

Init finds e2e by its packages, or by an `e2e.config.ts` that imports them. It writes the `flows` part below, with `--target` set to the config's iOS target. The other settings are optional. [keepsnappy.yml and run flags](https://keepsnappy.com/docs/settings.md#keepsnappyyml) lists every setting.

```yaml
verdict_gate: advisory
app:
  bundle_id: com.example.app
device: booted
flows:
  runner: command
  command: npx e2e run --target ios --retries 0 --strict-cache --exclude-tag ai
timeout_seconds: 900
```

KeepSnappy groups uploaded runs by [simulator runtime](https://keepsnappy.com/docs/settings.md#simulator-and-emulator-identity), so fresh leases on that runtime share one device history.

- `--retries 0`: a test that ran twice doesn't count, so e2e must not retry.
- `--strict-cache`: e2e can replay an AI step from its cache. With this flag, when the screen has changed, the step fails instead of calling the AI model again.
- `--exclude-tag ai`: leaves out the tests you tagged `ai`. It helps only once you have tagged them. Init lists each test file that uses AI steps and has no `ai` tag, and doesn't call the setup ready until you fix it.

After every run, KeepSnappy reads the `report.json` that e2e writes. It looks under `--output`, else under the `output` that `e2e.config.ts` sets, else under `.e2e`, from the folder of the e2e config (`--config`, or the nearest `e2e.config.ts`). A run with no new report there doesn't count, and the log prints the path it read. Give e2e an output directory inside its project, such as `.e2e-smoke`, and copy the report out afterward if your CI collects it elsewhere. If you set `flows.e2e_report`, point it at the report the command actually writes.

When a package script or a shell runs your tests, KeepSnappy can't see `e2e` in the command. It can't read an `output` that the config computes either. Then set `flows.e2e_report` to the report's path, or the runs are not checked. Init does this when a package script runs `e2e run`:

```yaml
flows:
  runner: command
  command: npm run test:e2e
  e2e_report: .e2e/report.json
```

## Journeys

One command is one journey, however many tests it runs. It is named `e2e`, or by `--scenario`. For a second journey, run a second command with its own name ([Journeys](https://keepsnappy.com/docs/journeys.md#any-other-test-command)).

A journey's name doesn't include the test tool. If you move a journey from another test tool to e2e, give it a new `--scenario` name. Otherwise the pull request is compared with `main` sessions that the old tool ran.

## Runs that don't count

A run doesn't count when its `report.json` shows one of the cases below. The log names the code, and the dashboard shows the reason with the run. The other runs of the session still count.

| The report shows | Code | The dashboard's reason |
|---|---|---|
| An AI step: `agent.act`, `agent.assert`, `agent.waitFor` or `agent.extract`, even a cached `act` that made no model call | `e2e-ai-step` | it ran an AI step; AI steps are not measured |
| A call to an AI model | `e2e-model-event` | it called an AI model; AI calls are not measured |
| A test that ran more than once | `e2e-retry` | the e2e runner retried a test, so the journey was not the same |
| No new `report.json` | `e2e-report-missing` | the e2e runner wrote no new report.json |
| A report in a format this version of KeepSnappy doesn't read | `e2e-report-schema` | its e2e report.json is in a format this CLI does not read |

Exploration (`explore`) is AI only. KeepSnappy refuses to wrap it and runs nothing.

## Journeys that measure the same way

KeepSnappy compares the journey with itself across commits, so the tests must do the same work every time. [Journeys](https://keepsnappy.com/docs/journeys.md#write-journeys-that-measure-the-same-way-every-run) has the rules for every test tool. In an e2e test:

- Use locators and `expect` only. Find elements with `getByTestId`. Use text only for content that has no other name.
- Use the same data every run ([why and how](https://keepsnappy.com/docs/journeys.md#use-the-same-data-every-run)). Reset the test account or the mock server through your backend, not by clearing the app.
- Start from the same state. `app.open()` starts the installed app. Reset test data before it, not inside the test.
- Wait on a condition. `expect` waits for its element, and fails when it doesn't show. Don't add fixed pauses.
- Don't check an element that the next step taps. The tap waits for it.
- Keep one path through the app per command, and end on the home screen.
- Put AI tests under a tag, such as `ai`. Leave them out with `--exclude-tag` or `--grep-invert`, or run them in a separate job that KeepSnappy doesn't wrap.

Keep the config and the tests in version control, and change them in their own pull request. A pull request that edits a test is compared with a `main` that ran the old test.

## CI example

[Init writes](https://keepsnappy.com/docs/ci.md#what-init-writes-in-your-workflow) a job like this for you, so copy this one only when init can't use your job. Like the [hand-made workflow](https://keepsnappy.com/docs/ci.md#a-complete-workflow), it runs the latest CLI release through `npx` and runs nightly at 03:00 UTC. It is one job on a macOS runner. It builds the app with the SDK and boots a simulator. Then it runs e2e once to prepare its runner, and runs `keepsnappy run` around its command.

```yaml
# .github/workflows/keepsnappy.yml
name: KeepSnappy
on:
  pull_request:
  push:
    branches: [main] # your default branch
  schedule:
    - cron: '0 3 * * *'
  workflow_dispatch:
jobs:
  keepsnappy:
    runs-on: macos-15
    timeout-minutes: 90
    env:
      KEEPSNAPPY: '1'
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: '24'
      - run: npm ci
      - name: Boot a simulator
        run: |
          UDID=$(xcrun simctl list devices --json | jq -r '[.devices[][] | select(.name == "iPhone 16" and .isAvailable)][0].udid')
          xcrun simctl boot "$UDID" || true
          xcrun simctl bootstatus "$UDID" -b
          echo "SIMULATOR_UDID=$UDID" >> "$GITHUB_ENV"
      - name: Build and install the KeepSnappy build
        run: |
          npx expo prebuild --platform ios
          npx expo run:ios --configuration Release --device "$SIMULATOR_UDID"
      # e2e compiles its iOS test runner on first use. One unmeasured call, so the first measured run does not pay for it.
      - name: Prepare the e2e runner
        continue-on-error: true
        run: npx e2e run --target ios --retries 0 --strict-cache --exclude-tag ai
      - name: Measure with KeepSnappy
        env:
          KEEPSNAPPY_KEY: ${{ secrets.KEEPSNAPPY_KEY }}
        run: >
          npx @keepsnappy/agent run --upload --wait
          --device "$SIMULATOR_UDID"
          --commit ${{ github.event.pull_request.head.sha || github.sha }}
```

- The test command comes from `flows.command` in `keepsnappy.yml`.
- A pull request gets its first real result once `main` has 3 sessions ([Getting started](https://keepsnappy.com/docs/getting-started.md#3-merge-then-measure-the-comparison-branch-3-times)).
- During the pilot, CI passes on a **Worse** ([why](https://keepsnappy.com/docs/ci.md#required-or-advisory-checks)).
- [Ready-made workflows](#ready-made-workflows) below are for the iOS simulator and for the Android emulator.

## Reuse a prebuilt iOS runner

The first iOS session can compile agent-device's XCUITest runner. Run the unmeasured preparation step on a host allowed to compile it. If you reuse a prebuilt runner with `AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH`, keep its Xcode build and agent-device runner sources matched to the test job. Local patches are part of those sources. A runner from the same package version can still be rebuilt if the sources differ.

For a custom simulator set, check that the e2e mobile provider passes the simulator set through to agent-device as well as the simulator UDID. On a cabled Android device, use the device serial explicitly. KeepSnappy passes it in `ANDROID_SERIAL`; configure your provider to pass that value as a serial rather than a device name.

On a shared test host, investigate an ownership error with the host's device allocator. If that allocator already gives each job exclusive use of its device, a job-specific `AGENT_DEVICE_CLAIMS_DIR` can isolate agent-device's own claim files. Keep the shared claim store when it is what enforces exclusive access.

## Ready-made workflows

The `@keepsnappy/agent` package ships two e2e workflows, one for the iOS simulator and one for the Android emulator, to use in place of the CI example above.

Copy `node_modules/@keepsnappy/agent/examples/e2e-github/keepsnappy-ios.yml` (iOS simulator) or `keepsnappy-android.yml` (Android emulator) from the installed CLI into `.github/workflows/`. Their `KEEPSNAPPY_CLI` is `@keepsnappy/agent`, the latest release. A copy from an older CLI names a version there: change it to `@keepsnappy/agent` before running it. Both use Node 24, a Release build with `KEEPSNAPPY=1`, and your existing e2e targets with retries disabled and a strict cache. Adapt the app identifiers, build paths and targets; the templates write `keepsnappy.yml`. Pin `e2e` and `@e2e-dev/mobile` to exact versions inside the tested range ([Install](#install) names it; the templates use the newest pair) and your SDK version in your lockfile ([versions that work together](https://keepsnappy.com/docs/install.md#versions-that-work-together)).

AI steps are refused, including cached agent actions; model calls, retries, missing reports and unknown report schemas also invalidate the run. Use scripted tests only.

Store the CI key as the repository secret `KEEPSNAPPY_KEY`. Android also needs the [SDK key](https://keepsnappy.com/docs/glossary.md#sdk-key) as the secret `EXPO_PUBLIC_KEEPSNAPPY_KEY`, the repository variable `KEEPSNAPPY_API` set to the API address from **Setup**, and the app's link scheme for the [activation](https://keepsnappy.com/docs/glossary.md#activation) and flush links. The Android build carries the SDK key and stays on the runner. Run on trusted pull requests: pull requests from forks get no repository secrets.

Both templates write a `keepsnappy.yml` with `verdict_gate: advisory`, as `init` does ([Required or advisory checks](https://keepsnappy.com/docs/ci.md#required-or-advisory-checks)). With `verdict_gate: blocking`, a blocking **Worse** on a pull request exits `3`, a verdict timeout exits `4`, and a session on `main` never fails because of its verdict or timeout.

## Known limits

- e2e paces its own steps, with settle and transition waits that you don't control. KeepSnappy doesn't measure those waits, but they change how often taps come. Keep both packages at the same versions on a pull request and on `main`.
- When e2e changes the format of `report.json`, runs don't count (`e2e-report-schema`) until KeepSnappy reads the new format.

## Other setups

- iOS, on an iPhone on a cable: not tried with e2e yet. [On your Mac](https://keepsnappy.com/docs/on-your-mac.md) runs any test command on a cabled iPhone, so check that a run counts before you trust the session.
- Android, on an emulator in your CI: start with `keepsnappy init --detect`. If init cannot use your emulator job, follow the [manual Android setup](https://keepsnappy.com/docs/android.md#android-emulator) and put your Android e2e command after `--` in the job. If both jobs share a config, `flows.command` in `keepsnappy.yml` keeps your iOS target.
- Android, on a phone on a cable: [Android](https://keepsnappy.com/docs/android.md#android-usb-phone) has the steps by hand, with your e2e command as `runner: command`.
- The report checks on this page apply to both Android setups.
- Real phones on BrowserStack, iOS or Android: e2e's BrowserStack package, `@e2e-dev/browserstack` 0.1.0, doesn't work with KeepSnappy yet. A BrowserStack session also ends at its time cap, about two hours, so all the runs of a long journey (5 by default) may not fit in one session.

[Troubleshooting](https://keepsnappy.com/docs/troubleshooting.md#e2e) lists what you may see with e2e, and how to fix it.

All KeepSnappy docs for agents: https://keepsnappy.com/llms.txt
