Files
e2e/docs/ci.mdx
T
Oskar Kwaśniewski 02ad48a94e feat(web)!: pin playwright-core and add a browser install command (#798)
* feat(web)!: pin playwright-core and add an install command

@e2e-dev/web depends on playwright-core 1.63.0 instead of peering on
playwright. New e2e-web bin installs browsers for the pinned version:
npx @e2e-dev/web install chromium --with-deps. e2e init no longer adds
playwright.

* test(web): run the e2e-web bin for real, and in CI

* test(web): spawn the built e2e-web bin so Node 22.12 runs it
2026-10-03 22:22:20 +02:00

215 lines
7.1 KiB
Plaintext

---
title: Continuous integration
description: Run tests on pull requests, upload reports, and configure model credentials in CI.
---
Run deterministic and agent tests in the same CI job. This workflow assumes
your config includes a [command](/starting-your-app) to start the app and
uses AI Gateway for model calls:
```yaml title=".github/workflows/e2e.yml"
name: e2e
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@9fd676a19091d4595eefd76e4bd31c97133911f1 # v4.2.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 26
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Install browsers
run: pnpm exec e2e-web install chromium --with-deps
- name: Run e2e
run: npx e2e run --reporter list,junit
env:
APP_URL: http://127.0.0.1:3000
AI_GATEWAY_API_KEY: ${{ secrets.AI_GATEWAY_API_KEY }}
E2E_USER_ADMIN_USERNAME: ${{ secrets.E2E_USER_ADMIN_USERNAME }}
E2E_USER_ADMIN_PASSWORD: ${{ secrets.E2E_USER_ADMIN_PASSWORD }}
- name: Upload report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: e2e-report
path: |
.e2e/report.json
.e2e/junit.xml
if-no-files-found: warn
- name: Upload artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: e2e-artifacts
path: .e2e/artifacts
if-no-files-found: warn
retention-days: 7
```
The workflow pins actions to commit SHAs and installs dependencies from the
lockfile. `npx e2e` runs the installed version. The
[install command](/reference/web#installing-browsers) downloads the browsers
for the Playwright version the engine pins, with their system libraries.
Artifacts upload on every run that is not cancelled, so a test that failed
and then passed on retry still has its evidence.
For iOS and Android suites, see [Mobile CI](/mobile-ci): GitHub Actions, EAS
Workflows, Bitrise, and Codemagic.
Configure your CI's test-report integration to read `.e2e/junit.xml`. It
includes startup failures such as `APP_UNREACHABLE` in a `run` suite. Add
the [GitHub reporter](/github) to post results on the pull request. Make the
e2e job a required check in your repository settings if it should block merges.
## What CI changes
CI mode is on when `CI` is set to a value other than an empty string, `0`,
or `false`. Use `CI=1 npx e2e run` to reproduce these defaults locally:
| Setting | Local | CI |
| --- | --- | --- |
| `retries` | `0` | `1` |
| `workers` | half your cores | `1` |
| `cache` when unset | `read-write` | `read-only` |
| `.only` | allowed | rejected with `ONLY_IN_CI` |
| `command.reuseExisting` | honored | ignored, with a notice |
Override worker and retry defaults with 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>
Add `E2E_TELEMETRY_DISABLED: '1'` to the job's `env` to send no
[telemetry](/telemetry#in-ci) from CI.
## Sharding
`--shard <index/total>` runs one slice of the suite per job. Every job runs
the same command with its own index, and the same suite shards the same way
on every machine. A shard that gets no test fails with `NO_TESTS`; add
`--pass-with-no-tests` when a matrix may have more shards than tests. The
[CLI reference](/reference/cli#flags) has the slicing rules.
```yaml
jobs:
e2e:
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
steps:
# ...
- run: npx e2e run --shard ${{ matrix.shard }}/3 --reporter list,junit
```
Each shard writes its own `report.json` and `junit.xml`; upload them under a
name that includes the shard index. Combining the documents into one is not
implemented yet.
## Rerunning failures
`--last-failed` runs only the tests the previous run did not pass, read from
`report.json` in the [`output`](/reference/config#output) directory (`.e2e`
by default). The rerun keeps the artifacts the first run's report names and
writes its own under `artifacts/rerun-1/`, so one upload after both steps
holds the evidence of each. A test another filter keeps out of the rerun
stays owed: the next `--last-failed` runs it. The
[CLI reference](/reference/cli#flags) lists what counts as not passed.
Locally it is the loop after a red run:
<CodeGroup>
```bash npm
npx e2e run
npx e2e run --last-failed
```
```bash pnpm
pnpm exec e2e run
pnpm exec e2e run --last-failed
```
```bash bun
bunx e2e run
bunx e2e run --last-failed
```
</CodeGroup>
In CI the report is a job artifact, not a file on the next runner; download
it into `.e2e/` before the rerun step, or rerun the failed job whole.
## Model credentials
Pass the credential your configured provider needs, such as
`AI_GATEWAY_API_KEY` in the workflow above. See [Models](/models)
for provider setup. Tests that never use `agent` need no model credentials.
Store keys in CI secrets and use spending limits where available. The code
running in the job can read those keys, including test code and dependencies.
GitHub withholds secrets from fork pull requests. Fully replayed action
steps need no model call, but live actions and agent judgments still do.
Run untrusted code without secrets or write tokens. See the
[security model](/security).
## Gating pull requests on agent steps
A failed agent step fails the job like a failed `expect`. Keep the checks
predictable by giving each `agent.act` one goal and checking its outcome
with a locator assertion or `agent.assert`.
To reuse verified actions in CI, [share the replay cache](/cache#commit-the-replay-cache).
A cache hit avoids a model call for that action step. Agent judgments still
run live, and a cache miss or hand-off uses the model.
CI retries once by default. A test that passes only on retry is reported as
flaky, so you can identify flows that need investigation.
`--max-failures <n>` stops the run once that many tests have failed, so a
broken deploy does not spend a model call on every remaining agent step. The
tests not started are skipped with cause `failure-limit`, the ones running
end as `interrupted`, counted apart from the failures, and the job exits 1.
## Exit codes
Any non-zero exit fails the job. [Debugging a run](/debugging#read-the-failure)
lists each code and whether a retry of the job can help.
<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>