> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Continuous integration

> Run e2e tests in CI on GitHub Actions, Vercel, GitLab CI/CD, Expo Workflows, Bitrise, Codemagic, Norrix, or any CI service that runs Node, with reports and sharding.

e2e works on any CI provider that runs Node 24.8+ (22.22.3+ on Node 22), or
[Bun](https://e2e.com/docs/reference/cli#bun) 1.4.3+ for web tests. A typical job installs
dependencies, starts the app or device, runs `e2e run`, and uploads `.e2e/`.

## Pick your CI service

<CardGroup cols={2}>
  <Card title="GitHub Actions" icon="/images/integrations/github-actions.svg" href="/ci/github-actions">
    Web and mobile workflows. Post the results as a pull request comment.
  </Card>
  <Card title="Vercel Previews" icon="/images/integrations/vercel.svg" href="/ci/vercel-previews">
    Test each deployment and hold production releases until the tests pass.
  </Card>
  <Card title="GitLab CI/CD" icon="/images/integrations/gitlab.svg" href="/ci/gitlab">
    Web and mobile jobs. Show the results in the merge request.
  </Card>
  <Card title="Expo Workflows" icon="/images/integrations/expo.svg" href="/ci/eas-workflows">
    Build an Expo app with Expo Build, then run iOS and Android tests on it.
  </Card>
  <Card title="Bitrise" icon="/images/integrations/bitrise.svg" href="/ci/bitrise">
    iOS and Android workflows with the Bitrise steps for simulators and emulators.
  </Card>
  <Card title="Codemagic" icon="/images/integrations/codemagic.svg" href="/ci/codemagic">
    iOS and Android workflows on Mac mini and Linux instances.
  </Card>
  <Card title="Norrix" icon="/images/integrations/norrix.png" href="/ci/norrix">
    Build a NativeScript app with Norrix, then run its suite on a Norrix simulator or emulator.
  </Card>
</CardGroup>

For another CI service, copy the [GitHub Actions](https://e2e.com/docs/ci/github-actions)
workflow. To lease browsers or devices from a hosted service, see
[Hosted browsers and devices](https://e2e.com/docs/integrations).

## Upload the reports

Always upload `.e2e/` at the end of a job, even when tests fail:

| Path | What's inside |
| --- | --- |
| `report.json` | Full JSON report for the run |
| `junit.xml` | JUnit XML (with `--reporter list,junit`), including filtered tests as skipped and startup failures |
| `results/` | Trace pages, screenshots, screen dumps, and videos (with `--video`) |

Point your CI provider's test-report view at `.e2e/junit.xml`. On GitLab,
`junit.xml` automatically links failure screenshots inline. You can move
`.e2e/` with the [`output`](https://e2e.com/docs/reference/config#output) option.

## Model credentials

Pass the API key your provider expects, such as `AI_GATEWAY_API_KEY` (see
[Models](https://e2e.com/docs/models)). Locator-only suites don't need any model key.

<Warning>
Any job with an API key exposes it to your test code, config, and
dependencies. Only give secrets to branches you trust. Run untrusted pull
request code with no secrets and no write tokens. See [Security](https://e2e.com/docs/security).
</Warning>

Store keys in CI secrets and set spending limits where your provider supports
them. GitHub Actions automatically withholds secrets from fork pull requests.

## What CI changes

CI mode turns on whenever the `CI` environment variable is set to anything
other than empty, `0`, or `false`. To test CI behavior locally, run
`CI=1 npx e2e run`.

By default, e2e uses one worker, retries failed tests once, and reads the
cache without writing. CI also rejects focused tests (`.only`) and ignores
`command.reuseExisting`. See [CI defaults](https://e2e.com/docs/reference/config#ci) for details.

To change the worker and retry defaults, use flags:

<CodeGroup>
```bash npm
npx e2e run --workers 4 --retries 0
```

```bash pnpm
pnpm exec e2e run --workers 4 --retries 0
```

```bash bun
bunx e2e run --workers 4 --retries 0
```
</CodeGroup>

To send no [telemetry](https://e2e.com/docs/telemetry#in-ci) from CI, add
`E2E_TELEMETRY_DISABLED: '1'` to the `env` of the job.

## Mobile jobs

Without a [hosted device service](https://e2e.com/docs/mobile#hosted-devices), each platform
needs its own machine, build, and device:

| | iOS | Android |
| --- | --- | --- |
| Machine | macOS with Xcode and a simulator runtime | Linux with KVM (nested virtualization) |
| Build | Release simulator `.app`, no signing | Release `.apk` |
| Device | A booted simulator | A booted emulator |

Make a Release build on both platforms. A React Native or Expo debug build
loads its JavaScript from Metro, which these jobs don't start, so it opens
on an error screen. The examples use a React Native project with `ios/` and
`android/` in the repository. For an Expo project without them, run
`npx expo prebuild` first.

Install the build, then run the suite:

<CodeGroup>
```bash npm
# iOS
xcrun simctl install booted path/to/MyApp.app
npx e2e run --target ios --reporter list,junit

# Android
adb install -r path/to/app.apk
npx e2e run --target android --reporter list,junit
```

```bash pnpm
# iOS
xcrun simctl install booted path/to/MyApp.app
pnpm exec e2e run --target ios --reporter list,junit

# Android
adb install -r path/to/app.apk
pnpm exec e2e run --target android --reporter list,junit
```

```bash bun
# iOS
xcrun simctl install booted path/to/MyApp.app
bunx e2e run --target ios --reporter list,junit

# Android
adb install -r path/to/app.apk
bunx e2e run --target android --reporter list,junit
```
</CodeGroup>

The commands assume two targets named `ios` and `android`, each a
`mobile()` engine with the app's `bundleId`. See
[Point at your app](https://e2e.com/docs/mobile#point-at-your-app). To let the suite install the
build, set `app.appPath` and call `device.installApp()`.

These rules apply on each service:

- **One job for each platform.** Run `--target ios` on a Mac and
  `--target android` on Linux with KVM. Hosted Macs use Apple Silicon,
  which can't nest virtualization, so the Android emulator doesn't start
  on them.
- **Boot the device in its own step.** With no device booted, the engine
  asks agent-device to boot one, but a new Linux runner has no emulator
  image. A separate step also tells a failed boot from a failed test.
- **Pin the iOS runtime.** A simulator picked by name (`iPhone 17`) runs
  the image's default iOS, and the accessibility tree changes between iOS
  releases. A runner image update can then fail a locator assertion with
  no change in your code. The examples create a simulator on a named
  runtime and boot it by UDID. Replace `iOS-26-5` with a runtime the image
  has (`xcrun simctl list runtimes`).
- **Cache `~/.agent-device/apple-runner/derived`.** agent-device builds
  its XCUITest runner there the first time it drives a simulator. Don't
  cache all of `~/.agent-device`. The rest is the state of the last
  daemon, and a restored copy can stop the next run with
  `Failed to communicate with daemon`.
- **Replay local recordings.** The replay cache key holds the app, not the
  device, so a step recorded on your simulator replays on the CI one.
  [Commit the replay cache](https://e2e.com/docs/cache#commit-the-replay-cache).

## Gate pull requests

Any non-zero exit fails the job, including failed agent steps. Make the e2e
job a required check to block merges on failures; don't rely solely on
counting failed tests from a report file, since that misses run-level errors.
See [Errors](https://e2e.com/docs/reference/errors#exit-codes) for the exit codes.

To keep PR checks fast and predictable:

- Give each `agent.act` the steps toward one [goal](https://e2e.com/docs/core-concepts#goals),
  followed by a locator assertion or `agent.assert`.
- [Commit the replay cache](https://e2e.com/docs/cache#commit-the-replay-cache) so recorded
  `agent.act` steps replay with zero model calls. (Cache misses, hand-offs,
  and agent judgments still call the model.)
- Watch for flaky tests: e2e flags any test that only passes on a retry as
  flaky.
- Use `--max-failures <n>` to bail out early on a broken deploy instead of
  burning model calls on every remaining test.
- Use `--max-duration <ms>` to cap test execution time (the timer starts once
  tests begin, excluding app startup).

## Run only affected tests

Pass `--changed-since` on pull requests so a [test filter](https://e2e.com/docs/filters) skips
tests that the diff is unlikely to affect and runs the riskiest files first.
Without the flag (such as on `main`), the full suite runs. See
[Add the decision filter](https://e2e.com/docs/filters#add-the-decision-filter).

## Cache the timings history

When running with multiple workers, `e2e run` uses `<output>/timings.json`
(`.e2e/timings.json` by default) to start the slowest test files first. Save
and restore this file in your CI cache so fresh checkouts keep the speedup.
See [GitHub Actions](https://e2e.com/docs/ci/github-actions#cache-the-timings-history) for an
example.

- It's purely advisory: a missing or invalid file never affects test results.
- Partial runs (`--grep`, `--last-failed`) don't overwrite timings for files
  they didn't run in full.
- Key the cache by branch with `main` as a fallback (and include the shard
  index if you use [sharding](#sharding)).
- Remember CI defaults to `workers: 1`; set `workers` or pass `--workers` to
  parallelize.

## Sharding

Pass `--shard <index/total>` to split a suite across parallel CI jobs. Every
machine slices the suite deterministically. If a shard can end up with zero
tests (for example, a matrix wider than the suite), add
`--pass-with-no-tests`. See the [CLI reference](https://e2e.com/docs/reference/cli#flags) for
slicing details.

On GitHub Actions, a matrix runs one job for each shard:

```yaml
jobs:
  e2e:
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3]
    steps:
      # ...
      - run: npx e2e run --shard ${{ matrix.shard }}/3 --pass-with-no-tests --output .e2e/shard-${{ matrix.shard }}
```

To rerun a shard's failures before uploading, run `e2e run --last-failed`
with that shard's original `--output`. Omit `--shard` so the rerun uses the
failures already selected from that shard.

Use a final job to publish one report for the matrix:

1. Upload each shard's output directory with `if: always()`. Include
   `report.json`, `report-with-reruns.json` when present, and `results/`.
2. Give the merge job `needs: e2e` and `if: always()`. Check out the same
   revision, install the project, and download the artifacts from this
   workflow run and attempt into separate directories such as
   `.e2e/shard-1`, `.e2e/shard-2`, and `.e2e/shard-3`.
3. Run [`e2e merge-reports`](https://e2e.com/docs/reference/cli#e2e-merge-reports) on those
   directories. Every shard must be present, including empty ones. Upload
   the entire merged directory with `if: always()` to keep trace links working.

<CodeGroup>
```bash npm
npx e2e merge-reports .e2e/shard-* --output .e2e/merged --reporter junit,markdown
```

```bash pnpm
pnpm exec e2e merge-reports .e2e/shard-* --output .e2e/merged --reporter junit,markdown
```

```bash bun
bunx e2e merge-reports .e2e/shard-* --output .e2e/merged --reporter junit,markdown
```
</CodeGroup>

Configure PR publishers such as `github()` only in the merge job, for
example by passing a separate `--config` there. Give that job the
publisher's permissions. If you keep the merge config in a subdirectory,
pass an absolute `--output` path to put the report outside that directory.
To rerun failures from the whole matrix, download the merged directory and
pass `--last-failed --output` with that directory's path to the run command.

## Rerunning failures

`--last-failed` reruns only the tests that failed in the previous run (read
from `.e2e/report.json`). You can chain it in the same CI step:

```yaml
      - run: npx e2e run || npx e2e run --last-failed
```

The rerun keeps the original artifacts, saves its own under `rerun-<n>/`, and
writes a combined `report-with-reruns.json` alongside `report.json`. If you
run the retry in a separate CI job, download the previous job's `report.json`
(plus `report-with-reruns.json` and `results/` if you want the full history).

## Next

<CardGroup cols={2}>
  <Card title="Pull request comments" icon="code-pull-request" href="/github">
    One comment per run, edited in place on a rerun.
  </Card>
  <Card title="CLI reference" icon="terminal" href="/reference/cli">
    Flags, reporters, and every exit code.
  </Card>
</CardGroup>
