> ## 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.

# test

> API reference for test in e2e, which declares tests, setup tests, groups, and hooks, sets options, skips tests, and adds fixtures with test.extend.

`test` declares tests, setup tests, groups, and hooks. Declarations run
synchronously while the test file is imported. Use `test.extend` to add
fixtures and `test.skip` to skip a test at registration or during its body.

```ts title="tests/checkout.e2e.ts"

describe('checkout', { tags: ['billing'] }, () => {
  beforeEach(async ({ app }) => {
    await app.open('/checkout');
  });

  test('pays with a saved card', { retries: 2 }, async ({ screen }) => {
    await screen.getByRole('button', 'Pay').tap();
    await expect(screen.getByText('Payment received')).toBeVisible();
  });
});
```

## Reference

### Members

| Member | Returns |
| --- | --- |
| [`test`](#test) | `TestCase` |
| [`test.skip`](#test-skip) | `TestCase \| void` |
| [`test.todo`](#test-todo) | `TestCase` |
| [`test.fixme`](#test-fixme) | `TestCase \| void` |
| [`test.skipIf`](#test-skipif) | `TestRegistrar` |
| [`test.runIf`](#test-runif) | `TestRegistrar` |
| [`test.each`](#test-each) | `EachRegistrar` |
| [`test.for`](#test-for) | `EachRegistrar` |
| [`test.fail`](#test-fail) | `TestCase \| void` |
| [`test.setTimeout`](#test-settimeout) | `void` |
| [`test.slow`](#test-slow) | `void` |
| [`test.step`](#test-step) | `Promise<T>` |
| [`test.only`](#test-only) | `TestCase` |
| [`test.setup`](#test-setup) | `TestCase` |
| [`test.extend`](#test-extend) | `TestAPI` |
| [`describe`](#describe) | `void` |
| [`describe.fail`](#describe-fail) | `void` |
| [`describe.configure`](#describe-configure) | `void` |
| [`describe.only`](#describe-only) | `void` |
| [Hooks](#hooks) | `void` |

`describe` and the four hooks are also top-level exports, the same functions
as `test.describe`, `test.beforeEach`, and the rest:
`import { describe, beforeEach, test } from 'e2e'`.

- A per-test hook imported from `e2e` is typed with the [built-in fixtures](#fixtures)
  every engine has.
- `@e2e-dev/web`, `@e2e-dev/mobile`, `@e2e-dev/desktop`, and
  `@e2e-dev/electron` export `test`, `describe`, and all four hooks typed
  with their `browser`, `device`, `desktop`, or `electron` fixture, so a test
  file registers from one import.
- A `test` you extended with your own fixtures registers hooks that see them
  through `test.beforeEach`.

Registering a test, group, or hook outside module evaluation throws
`COLLECTION_ERROR`. The full declarations are under [Types](#types).

#### `test`

Registers one test, with or without [options](#options).

```ts

test('app opens', async ({ app, browser }) => {
  await app.open();
  await expect(browser).toHaveURL('/');
});

test('checks out', { tags: ['billing'], retries: 2, timeout: 60_000 }, async ({ app }) => {
  await app.open('/checkout');
});
```

A test or group title is 1 through 512 UTF-8 bytes after NFC normalization,
with no NUL character.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | Two tests in one file share a title path: the group titles, then the test's own. |

#### `test.skip`

Registers a skipped test, or skips the running test.

```ts
test.skip('exports a PDF', async ({ app }) => {}); // at registration
test.skip(organizations.length < 2, 'a single organization'); // inside a body
test.skip('not on this tenant'); // inside a body, always
```

- A skipped test does not affect the exit code by default.
- To skip at collection by option, use the [`skip`](#skip) option.
- At registration it returns a `TestCase`; inside a body, `void`.

Inside a body, for a condition you learn at runtime:

- When the condition is true, the call throws, as Playwright's does. Nothing
  after the call runs.
- With no failure before it, the test is reported `skipped` with `reason`,
  with no retry.
- Steps before it stay in the report as they ran.
- A failed `expect.soft` before the call still fails the attempt, as in
  Playwright. The attempt is `failed`, with the soft failures as its error and
  the skip reason in its `skip`. It retries like any failure.
- Hooks and fixtures still run their teardown.
- When the condition is a precondition, call it first, before any step.
- A failed attempt followed by a skip on retry leaves the test `skipped`. The
  CLI lists it under `Skipped After Failure` with its original error. Set
  [`failOnSkippedFailure: true`](https://e2e.com/docs/reference/config) to fail the run with exit
  code 1 in that case. The default is `false`.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | Called in a setup test with a true condition, or none. A setup test cannot skip because other tests depend on its sessions. |
| `COLLECTION_ERROR` | The conditional form, outside a test body. |
| `COLLECTION_ERROR` | The registration form, inside a serial group. Set [`skip`](#skip) on the serial `describe` instead. |

#### `test.todo`

Registers an unfinished test without a body:

```ts
test.todo('add checkout coverage');
```

- The test never runs and has no attempts. It is reported `skipped`, with
  `skip.cause` and `skip.reason` both `todo`.
- A selection of only TODO tests fails with `NO_TESTS` unless
  `--pass-with-no-tests` is set.
- It takes no test options and returns a `TestCase`.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | Called with a body or any argument after the title. Use [`test.skip`](#test-skip) or [`test.fixme`](#test-fixme) for a test with a body. |
| `COLLECTION_ERROR` | Called inside a serial group. Set [`skip`](#skip) on the serial `describe` instead. |

#### `test.fixme`

Registers a skipped test marked fixme, or skips the running test as fixme.

```ts
test.fixme('exports a PDF', async ({ app }) => {}); // at registration
test.fixme(platform === 'android', 'crashes on Android'); // inside a body
test.fixme(); // inside a body, always
```

- It takes the same three forms as [`test.skip`](#test-skip), and the rules of
  its body form apply.
- The test is reported `skipped`, with `skip.cause` `fixme` in
  `report.json` where `test.skip` reports `explicit`. The reason is `fixme`,
  or `fixme: <reason>` when a call inside a body gives a reason that is not
  blank. The list reporter shows it as `[fixme: crashes on Android]`.
- The registration form takes no test options.
- At registration it returns a `TestCase`; inside a body, `void`.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | Called in a setup test with a true condition, or none. A setup test cannot skip because other tests depend on its sessions. |
| `COLLECTION_ERROR` | The conditional form, outside a test body. Use `test.fixme(title, fn)` at collection. |
| `COLLECTION_ERROR` | The registration form, inside a serial group. Set [`skip`](#skip) on the serial `describe` instead. |

#### `test.skipIf`

Returns a function that registers one test, like `test(title, fn)`, skipped
when the condition is truthy.

```ts
test.skipIf(process.platform === 'win32')('watches files', async ({ app }) => {});
test.skipIf(process.env.CI)('opens the system dialog', async ({ app }) => {});
```

- The condition is read once, at the call, while the file is collected.
  Use a value known then, such as `process.platform` or an environment
  variable. For a condition you learn at runtime, call
  [`test.skip(condition, reason)`](#test-skip) inside the body.
- Any truthy value skips, as in Vitest.
- A skipped test is the same as `test(title, { skip: true }, fn)`: its body
  never runs, and its other options are kept.
- A [`skip`](#skip) option skips the test whatever the condition, and its
  reason string is the reported reason.
- It takes the same two forms as [`test`](#test) and has the same fixtures,
  on an extended `test` too.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | Called inside a serial group, whatever the condition. Set [`skip`](#skip) on the serial `describe` instead. |
| `COLLECTION_ERROR` | The condition is a Promise, which is also a type error. Await it before the call. |

#### `test.runIf`

Returns a function that registers one test, like `test(title, fn)`, skipped
when the condition is falsy.

```ts
test.runIf(process.platform === 'linux')('reads inotify events', async ({ app }) => {});
```

`test.runIf(condition)` is `test.skipIf(!condition)`.
Everything in [`test.skipIf`](#test-skipif) applies.

#### `test.each`

Returns a function that registers one test per row, like `test(title, fn)`,
in row order. Use it for the same steps with different data.

```ts
test.each([{ user: 'Ada' }, { user: 'Grace' }])('signs in as $user', async ({ user }, { app }) => {
  await app.open();
  // ...
});

test.each([
  ['standard', '5.00'],
  ['express', '15.00'],
])('ships %s for %s', async (speed, price, { screen }) => {});
```

- The body gets the row first and the fixtures last. When every row is an
  array, each row is spread, so `[speed, price]` arrives as
  `(speed, price, fixtures)`. When any row is not an array, every row
  arrives whole, as `(row, fixtures)`, as in Vitest and Jest.
- The body names the [fixtures](#fixtures) it uses by destructuring the
  parameter after the row, and e2e sets up only those. A body that uses none
  can leave the parameter out.
- The title is formatted from the row:

  | In the title | Becomes |
  | --- | --- |
  | `$name`, `$name.path` | That key of an object row. A string shows as written, any other value as Node's `inspect` shows it. |
  | `%s` | The next item, shown the same way. |
  | `%o` | The next item as Node's `inspect` shows it, so a string is quoted. |
  | `%d` | The next item as a number (`Number(item)`), except a `BigInt` keeps its `n` suffix and a `Symbol` shows as `NaN`. |
  | `%i`, `%f` | The next item read as an integer or a float, like `parseInt` / `parseFloat`: `'42px'` becomes `42`. A `BigInt` keeps its `n` suffix under `%i`. |
  | `%j` | The next item as JSON. A circular value shows as `[Circular]`; a function, a `Symbol`, or `undefined` as `undefined`. |
  | `%#`, `%$` | The row index, from 0, and the row number, from 1. |
  | `%%` | A percent sign. |

  The items are an array row's items in order; any other row is the one
  item. A placeholder with no item left, or `$name` on a row that is not an
  object, stays as written. A value other than a string always shows on one
  line; a string shows as written, line breaks included. An `Error` shows
  as its name and message, without its stack.
- A title is part of the test id. `%#` and `%$` change when rows are added or
  moved, so prefer `$name` or a value placeholder for ids that stay stable.
- Titles differ from Vitest in a few places: `$0` and `$1` do not read an
  array row, `$name` is not read from an array row's first item, `%s` shows
  an object with `inspect`, not its own `toString` (a `URL` is not shown as
  its href), `%O` and `%c` are not placeholders, and a table written as a template
  literal is not read. The body differs too:
  Vitest's `test.each` body gets only the row, while here the fixtures
  come after it.
- Each row is a separate test, with its own id, report entry, and retries.
  Options apply to every row, so a [`skip`](#skip) or [`tags`](#tags)
  option skips or tags them all.
- It takes the same two forms as [`test`](#test) and has the same fixtures,
  on an extended `test` too.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | The rows are not an array, the array is empty, or the rows are a template literal table. |
| `COLLECTION_ERROR` | Two rows format to the same title. Put a placeholder in the title that tells the rows apart. |
| `COLLECTION_ERROR` | A `%j` item cannot be turned into JSON for a reason other than a cycle, such as a `BigInt`. The message names the row. |
| `COLLECTION_ERROR` | The body takes the fixtures whole (`async (row, fixtures) => {}`) or in a rest parameter (`async (...args) => {}`), or breaks another [fixture naming rule](#fixtures). |

#### `test.for`

[`test.each`](#test-each), except an array row is not spread: the body
always takes `(row, fixtures)`. Titles are formatted the same way.

```ts
test.for([
  ['standard', '5.00'],
  ['express', '15.00'],
])('ships %s for %s', async ([speed, price], { screen }) => {});
```

#### `test.fail`

Registers a test that is expected to fail, or marks the running test.

```ts
test.fail('shows the cart badge', async ({ app, screen }) => {}); // at registration
test.fail(platform === 'web', 'tap on a display: contents element'); // inside a body
test.fail('known gap'); // inside a body, always
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {}); // by option
```

To mark every test in a group, use [`describe.fail`](#describe-fail).

- The body keeps running after the call. A `beforeEach` hook can mark the
  test too.
- A failed assertion, action, thrown error, or timeout makes the test
  `passed`. The report keeps the reason and the error.
- A pass makes the test `failed` with `UNEXPECTED_PASS`. Remove the mark
  once the cause is fixed.
- Infrastructure errors, interrupts, a failed `beforeAll` or `afterAll`, and
  API misuse such as `INVALID_ARGUMENT` still fail the test.
- An expected failure is not retried. An unexpected pass is.
- A skip wins over the mark.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A true condition in a setup test, a serial group member, an `afterEach` hook, or a fixture teardown. |
| `COLLECTION_ERROR` | The conditional form, outside a test body, or the `fail` option inside a serial group. |

#### `test.setTimeout`

Changes the running test's timeout from its body or a `beforeEach` hook, or a
`beforeAll` hook's own timeout from inside it.

```ts
test('imports a large file', async ({ app }) => {
  test.setTimeout(180_000);
  await app.open('/import');
});
```

- The new timeout counts from the start of the attempt, like the
  [`timeout`](#timeout) option, and replaces it for this attempt. A retry
  starts from the option again.
- A timeout shorter than the time already spent times the test out at once.
- In a `beforeAll` hook, it replaces that hook's timeout, the config
  `timeout`, counted from the hook's start. The tests keep their own.
- `afterEach` and `afterAll` hooks and fixture teardowns run on
  `cleanupTimeout`, so they cannot change it.
- A session from [`host.openSession`](https://e2e.com/docs/reference/runner#host-opensession) runs
  no e2e test, so it cannot either. Pass `timeout` to `host.openSession`.
- There is no `0` for no timeout. Pass a large value instead.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A timeout that is not a positive safe integer of milliseconds, one above 2147483647, or a call from an `afterEach` or `afterAll` hook, a fixture teardown, or a hosted session; or from code a test or hook left running after it ended. |
| `COLLECTION_ERROR` | A call outside a running test or hook. Use the `timeout` option there. |

#### `test.slow`

Triples the running test's timeout, as Playwright's `test.slow()` does. Call
it from the test body or a `beforeEach` hook, or from a `beforeAll` hook to
triple that hook's timeout.

```ts
test('imports a large file', async ({ app }) => {
  test.slow();
  await app.open('/import');
});
test('renders the report', async ({ platform }) => {
  test.slow(platform === 'ios', 'the simulator renders slowly');
});
```

- It triples the timeout in force, counted from the start of the attempt
  like [`test.setTimeout`](#test-settimeout), whose rules it follows. After
  `test.setTimeout(10_000)` it gives 30 seconds, up to 2147483647
  milliseconds.
- As in Playwright, it slows an attempt once: a second call, in the body or
  a `beforeEach` hook, does nothing. A later `test.setTimeout` still
  replaces the timeout.
- With a false condition it does nothing. The reason is for the reader and
  is not reported.
- There is no `test.slow(title, fn)`. Call `test.slow()` first in the body,
  or pass `timeout`.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A call from an `afterEach` or `afterAll` hook, a fixture teardown, or a hosted session; or from code a test or hook left running after it ended. |
| `COLLECTION_ERROR` | A call outside a running test or hook, even with a false condition, or `test.slow(title, fn)`. Use the `timeout` option there. |

#### `test.step`

Runs a function as one step with a name of your own. Reports show the name,
with the calls the function makes nested under it.

```ts
test('buys a ticket', async ({ screen }) => {
  await test.step('Log in as test user', async () => {
    await screen.getByLabel('Email').fill('ada@example.com');
    await screen.getByRole('button', 'Log in').tap();
  });
  const total = await test.step('Read the total', () => screen.getByTestId('total').textContent());
});
```

- It returns what the function returns.
- Steps nest: a `test.step` inside another is listed under it.
- When the function throws, the step is failed and the error goes on to the
  test. Catch it to continue.
- Call it in a test body, a `beforeEach` or `afterEach` hook, or a fixture.
  In a `beforeAll` or `afterAll` hook, a worker fixture, or an `openHost()`
  session the function runs, but no report has the step.
- In a fixture, call it before or after `use()`. In a test-scoped fixture, a
  `test.step` around `use()` fails the test with `STEP_NOT_AWAITED`.
- A failed [`expect.soft`](https://e2e.com/docs/reference/expect#soft-assertions) inside it does not
  fail the step. A `test.skip()` inside it skips the test and the step
  passes.
- [`e2e run --step`](https://e2e.com/docs/reference/cli#e2e-run) stops before each call inside
  it, not before the `test.step` itself.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A title that is not a non-empty string, or no function. |
| `CANCELLED` | A call from work its phase left running, such as a body or hook past its timeout. |
| `COLLECTION_ERROR` | Any other call outside a running test, hook, fixture, or `openHost()` session, such as one at collection. |

#### `test.only`

Registers one focused local test.

```ts
test.only('pays', async ({ app }) => {
  await app.open('/checkout');
});
```

Other tests are reported as `filtered`. A CI run with a focused test fails
with `ONLY_IN_CI`. To focus every test in a group, use
[`describe.only`](#describe-only).

#### `test.setup`

Registers a setup test that declares the sessions it saves, and must save
each exactly once.

```ts

test.setup('authenticate', { sessions: ['member'] }, async ({ app, screen, session }) => {
  await app.open('/login');
  await screen.getByLabel('Email').fill(credentials.user('member').username);
  await screen.getByLabel('Password').fill(credentials.user('member').password);
  await screen.getByRole('button', 'Sign in').tap();
  await session.save('member');
});
```

- `test.setup` must be top-level, not inside `describe`.
- The [`sessions`](#sessions) option declares the names.
- A test consumes a saved session with the [`session`](#session) option.
- The setup body gets one extra fixture, `session`:

```ts
export interface SetupSession {
  save(name: string): Promise<void>;
}
```

| Throws | When |
| --- | --- |
| `SESSION_CONTRACT` | At runtime, a declared session was not saved, or was saved twice. |

#### `test.extend`

Returns a new `test` typed with more fixtures. The one it was called on is
unchanged.

```ts

export const test = base.extend<{ device: Device }>(); // types only
```

- With no argument, `extend` refines only the types: it returns the same
  runtime `test`, typed with the built-in fixtures an engine contributes. They still
  resolve from the target's engine at runtime. This types a device, desktop,
  or web surface without a global `declare module` augmentation.
- With definitions, it adds fixtures of your own. See
  [Your own fixtures](#your-own-fixtures).
- The type arguments, in order:
  1. Test fixtures.
  2. [Worker fixtures](#worker-fixtures), which are available in `beforeAll`
     and `afterAll`. `device`, `app`, and `screen` from `@e2e-dev/mobile` are
     typed here.
  3. The config's type (`typeof config`), used to type fixtures from the
     config.
     See [Engine fixtures across targets](#engine-fixtures-across-targets).

#### `describe`

Declares a group of tests, with or without options.

```ts

describe('checkout', { tags: ['smoke'], serial: true }, () => {
  test('adds an item', async ({ screen }) => {});
  test('pays', async ({ screen }) => {});
});
```

- A group takes the [options](#options) a test takes, plus
  [`serial`](#serial) and [`parallel`](#parallel).
- The body is synchronous.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | An `async` body. It is also a type error. |
| `COLLECTION_ERROR` | `test.setup` inside the body. |

#### `describe.fail`

Declares a group whose tests are all expected to fail, the same as
`fail: true` on `describe`. For a reason, use the [`fail`](#fail) option.

```ts
describe.fail('legacy checkout', () => {
  test('pays by card', async ({ screen }) => {}); // expected to fail
  test('applies a coupon', async ({ screen }) => {}); // expected to fail
});
describe('legacy checkout', { fail: 'old payment form' }, () => {}); // with a reason
```

- Each test is judged on its own, as with [`test.fail`](#test-fail): a
  failure passes it, and a pass fails it with `UNEXPECTED_PASS`.
- A `fail` reason on a test or an inner group wins over an outer one.
  `fail: false` on a test or an inner group does not unmark it.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | The group is serial or inside a serial group, or a serial group is inside it. |
| `COLLECTION_ERROR` | A `fail` option on `describe.fail`. It is also a type error. |

#### `describe.configure`

Sets [`parallel`](#parallel) on the scope it is called in: the enclosing
`describe`, or the whole file at the top level.

```ts

describe.configure({ parallel: true }); // every test of this file

test('lists orders', async ({ screen }) => {});
test('lists invoices', async ({ screen }) => {});
```

- The call can come before or after the tests of its scope.
- `{ parallel: false }` at the top level keeps the file in order under
  [`fullyParallel`](https://e2e.com/docs/reference/config#fullyparallel).

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | `parallel` is already set for the scope, by the `describe` option or an earlier call. |
| `COLLECTION_ERROR` | A key other than `parallel`. |
| `COLLECTION_ERROR` | Any case [`parallel`](#parallel) lists. |

#### `describe.only`

Declares a focused group, the same as `only: true` on `describe`. Every
test in it, nested groups included, is focused the way
[`test.only`](#test-only) focuses one.

```ts
describe.only('checkout', () => {
  test('pays by card', async ({ screen }) => {}); // runs
  describe('refunds', () => {
    test('refunds a card', async ({ screen }) => {}); // runs
  });
});
test('signs in', async ({ app }) => {}); // filtered
describe('checkout', { only: true }, () => {}); // the same, by option
```

- Focused groups and `test.only` combine: every focused test runs, and the
  rest are reported as `filtered`.
- A `test.only` or `describe.only` inside a focused group narrows that
  group, as in Playwright: of its tests, only the inner focused ones run.
- A skipped test in a focused group stays focused and is reported with its
  own skip cause, `explicit`, `fixme`, or `todo`.
- A CI run with a focused group fails with `ONLY_IN_CI`.
- A serial group can be focused whole.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | The group is inside a serial group. |
| `COLLECTION_ERROR` | An `only` option on `describe.only`. It is also a type error. |

### Hooks

| Hook | Runs |
| --- | --- |
| [`beforeEach`](#beforeeach) | Before each test attempt |
| [`afterEach`](#aftereach) | After each test attempt |
| [`beforeAll`](#beforeall) | Once per suite instance |
| [`afterAll`](#afterall) | After the scope's last test |

Hook order follows scope nesting, not position in the file, so a hook
declared after a test still applies to it.

#### `beforeEach`

Registers a test-attempt setup hook.

```ts
test.beforeEach(async ({ app }) => {
  await app.open('/');
});
```

- Runs outermost group first, then in declaration order within a group.
- `beforeEach` and the body share the test timeout.
- Receives the test fixtures. The ones it names are set up for every test it
  applies to. See [Your own fixtures](#your-own-fixtures).

#### `afterEach`

Registers a test-attempt teardown hook.

```ts
test.afterEach(async ({ app }) => {
  await app.screenshot('after');
});
```

- Runs innermost group first, in reverse declaration order, after a failure
  or timeout too.
- Each `afterEach` hook gets its own `cleanupTimeout` budget with working
  fixtures, so teardown can still drive the app after the body timed out.
- Receives the test fixtures. The ones it names are set up before the first
  `beforeEach`, on the test timeout, never when the hook starts.
- A hook that names a fixture whose setup failed is skipped.

#### `beforeAll`

Registers a suite-instance setup hook. It runs once per suite instance, on
first entry into the scope.

```ts
test.beforeAll(async ({ database, device }) => {
  await database.seed();
  await device.setPermission('camera', 'deny'); // a mobile target
});
```

The module is re-imported for every retry, serial group, and setup test, so
`beforeAll` runs again in each, and in each batch of a
[parallel](#parallel) scope.

It receives [worker fixtures](#worker-fixtures) only:

- The [built-in fixtures](#fixtures) whose scope is worker on the target:
  `platform`, `services`, and on a mobile target `device`, `app`, and `screen`.
- The worker fixtures of the `test` it was registered through. The ones it
  names are set up, and the ones declared with `auto: true`.

On a browser target, `browser`, `app`, and `screen` are test fixtures. Put UI
setup in `beforeEach`.

On a mobile target, `beforeAll` and `afterAll` hooks launch nothing. When
the engine cannot open for them, or the run was interrupted, the hooks still
run. Reading `device`, `app`, or `screen` then throws with the reason. A
failed open is one run error in phase `launch`.

The steps a suite hook takes are in no test's record. A failure names the
hook's scope.

Each `beforeAll` hook runs on the config `timeout`.
[`test.setTimeout`](#test-settimeout) or [`test.slow`](#test-slow) inside it changes that hook's
timeout. The worker fixtures the hook names are set up before its body runs, so they
keep the config `timeout`.

| Throws | When |
| --- | --- |
| `HOOK_FAILED` | The hook throws. The suite's tests are skipped with cause `hook-failed`. Inside a serial group it skips every remaining member and fails the group without a retry. |
| `COLLECTION_ERROR` | The hook names a test fixture. The message names it and the hook's line, and no test runs. |

#### `afterAll`

Registers a suite-instance teardown hook. It runs as soon as the scope's last
test is done.

```ts
afterAll(async () => {
  await resetDatabase();
});
```

After a failure, `afterAll` still runs for every scope a test entered,
including one with no `beforeAll`. It cannot run when the worker itself is
killed. It receives the same fixtures as
[`beforeAll`](#beforeall) and has `cleanupTimeout` to finish. A throw is
`HOOK_FAILED`, as for `beforeAll`.

#### Blocked event loop

A test that blocks its worker's event loop (`while (true) {}` in a fixture,
`beforeEach`, the body, or `afterEach`) cannot be timed out by that worker.

- When the worker has not responded `cleanupTimeout` (at least 5 s) after the
  test timeout, the runner kills it.
- That attempt is reported `timed-out` with `TEST_TIMEOUT` and no artifacts,
  after the attempts before it, and is not retried.
- The rest of its file runs on a new worker. In a serial group, the members
  after it are skipped.
- A `beforeAll` or `afterAll` that blocks still hangs the run.

<Note>
A worker with a debugger attached when the test starts (an editor's
auto-attach, or `NODE_OPTIONS=--inspect=0`) is never killed this way, so a
breakpoint can stay paused. A programmatic run with an inline config or
in-memory tests runs in the runner's own process and has no worker to kill: a
blocked event loop hangs it.
</Note>

### Options

| Option | Type | Default |
| --- | --- | --- |
| [`timeout`](#timeout) | `number` | `config.timeout` |
| [`retries`](#retries) | `number` | `config.retries` |
| [`tags`](#tags) | `readonly string[]` | - |
| [`skip`](#skip) | `boolean \| string` | - |
| [`fail`](#fail) | `boolean \| string` | - |
| [`only`](#only) | `boolean` | - |
| [`platforms`](#platforms) | `readonly string[]` | - |
| [`session`](#session) | `string` | - |
| [`agentContext`](#agentcontext) | `string` | - |
| [`agent`](#agent) | `string \| readonly string[]` | the run's agents |
| [`trace`](#trace) | `RecordingMode` | the run's |
| [`video`](#video) | `RecordingMode` | the run's |
| [`serial`](#serial) | `boolean` | - |
| [`parallel`](#parallel) | `boolean` | - |
| [`sessions`](#sessions) | `readonly string[]` | required |

`test` takes every option but `serial`, `parallel`, and `sessions`. `describe` takes
every option but `sessions`. `test.setup` requires
`sessions` and takes no `session`, `only`, `skip`, or `fail`.

Resolution order: test, nearest group, outer groups, config, built-in
default. Inside a [serial group](#serial), the group's `retries`, `trace`, and
`video` apply.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | An option key the call does not take (`{ timout: 1000 }`). The error names the nearest known key when it is a likely typo, and every key the call takes otherwise. |

#### `timeout`

The attempt deadline in milliseconds. Innermost wins.

```ts
test('imports a large file', { timeout: 300_000 }, async ({ app }) => {}); // default: config.timeout
```

`timeout` must be a positive safe integer, at most 2147483647 (about 24 days).

#### `retries`

How many times a failed test is retried.

```ts
test('checks out', { retries: 2 }, async ({ app }) => {}); // default: config.retries
```

An integer from 0 through 10.

#### `tags`

Tags that `--tag` selects on. Every layer's tags are unioned.

```ts
describe('checkout', { tags: ['billing', 'smoke'] }, () => {});
```

Tags are distinct names, none blank, with no comma and no leading or
trailing whitespace.

#### `skip`

Skips the test at collection. A string is the reason. Any truthy layer skips.
Skip reasons, including runtime `test.skip` reasons, are secret-redacted,
sanitized, and limited to 8,192 UTF-8 bytes before reporting.

```ts
test('exports a PDF', { skip: 'PDF export is off on staging' }, async ({ app }) => {});
```

#### `fail`

Expects the test to fail; see [`test.fail`](#test-fail). A string is the
reason. A layer with `true` or any string marks, and the innermost reason
wins. Not allowed on, inside, or around a serial group.

```ts
test('exports a PDF', { fail: 'PDF export is broken' }, async ({ app }) => {});
describe('legacy checkout', { fail: 'old payment form' }, () => {});
```

#### `only`

Focuses the test locally, or every test in a group; see
[`describe.only`](#describe-only). CI rejects it with `ONLY_IN_CI`.

```ts
test('pays', { only: true }, async ({ app }) => {});
describe('checkout', { only: true }, () => {});
```

#### `platforms`

Platforms the test runs on. Other targets skip it. Innermost wins.

```ts
test('uses Face ID', { platforms: ['ios'] }, async ({ app }) => {});
```

#### `session`

The session a setup test saved, restored before the body runs.

```ts
test('sees the dashboard', { session: 'member' }, async ({ app }) => {});
```

See [`test.setup`](#test-setup).

#### `agentContext`

Extra context for agent steps. Layers are concatenated outermost first.

```ts
describe('pricing', { agentContext: 'Prices are shown in EUR.' }, () => {});
```

#### `agent`

The configured agent (`agents.<name>`) this test or group runs with, in
place of the run's agents.

```ts
test('checks out', { agent: ['fast', 'smart'] }, async ({ agent }) => {}); // one result per agent
```

- A list runs the test once per agent named, as one result each.
- Innermost wins. A call's own `agent` option wins over it.
- `--agent` narrows a list to the names both name, and never overrides a pin
  the flag does not name.
- A setup test runs once per target, so it pins at most one agent.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | At selection, before any test runs: a name that `agents` does not define. |

#### `trace`

Whether the test keeps a trace page, in place of the run's.

```ts
test('checkout', { trace: 'retain-on-failure' }, async ({ agent }) => {});
```

- Takes a [recording mode](https://e2e.com/docs/reference/config#recording), the same as the
  config's `trace`: `off`, `on`, `retain-on-failure`, `on-first-retry`, or
  `on-all-retries`.
- A test's or group's own value wins over `--trace`, the target's, and the
  config's. One test can record on a run that records nothing, or opt out of
  one that records everything.

#### `video`

Which of the test's attempts record a video, in place of the run's.

```ts
test('checkout', { video: 'on' }, async ({ agent }) => {
  await agent.act('Buy the first product in the catalog');
});
```

- Takes the same [recording modes](https://e2e.com/docs/reference/config#recording) as `trace`
  and the config's `video`.
- A test's or group's own value wins over `--video`, the target's, and the
  config's.

| Throws | When |
| --- | --- |
| `UNSUPPORTED_ARTIFACT` | Before any test starts, naming the test: the mode records on some attempt and the target's engine cannot record video. |

#### `serial`

`describe` only. Runs the group as one ordered retry unit with shared app
state.

```ts
describe('checkout', { serial: true }, () => {
  test('adds an item', async ({ screen }) => {});
  test('pays', async ({ screen }) => {});
});
```

- The group also shares secret state: a value one member resolves stays
  redacted for the rest of the group's attempt. A retry starts fresh.
- Members take the `trace` and `video` on the serial `describe` or a group
  around it. The group records one video per group attempt.
- A group attempt may not start because its file fails to load or its session
  fails to launch. Then the first member fails with that error, and the rest
  skip with cause `serial-predecessor-failed`. When the run is interrupted
  during the launch, every member skips instead.
- If a retry is interrupted or never reaches its members, they keep the
  verdicts and durations of the last attempt that ran them.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | A member sets `retries`, `trace`, `video`, `session`, `platforms`, `skip`, `only`, or a nested `serial`. |
| `COLLECTION_ERROR` | A member registers through `test.skip(title, fn)`, `test.todo(title)`, `test.skipIf`, `test.runIf`, or `test.fixme(title, fn)`. |

#### `parallel`

`describe` only. `true` runs the group's tests at the same time on separate
workers. By default, a file's tests run in order on one worker.

```ts
describe('reports', { parallel: true }, () => {
  test('exports a CSV', async ({ screen }) => {});
  test('exports a PDF', async ({ screen }) => {});
});
```

- For a whole file, call [`describe.configure`](#describe-configure) at the
  top level. For every file, set
  [`fullyParallel`](https://e2e.com/docs/reference/config#fullyparallel).
- Tests that run apart on the same worker share the state in the test
  file. Tests on different
  workers do not, so keep no state in the file that one test leaves for
  another. A `beforeAll` and its `afterAll` can run several times on that
  state, so create in `beforeAll` what `afterAll` closes.
- Declare shared tests and hooks in ES modules of your project. A CommonJS
  module, a package from `node_modules`, and every imported
  module on Bun stays one instance, so the tests and hooks it declares
  are missing from a retry, from the tests after a failed one, and from a
  second file that imports it.
- A [serial](#serial) group inside a parallel scope still runs as one unit
  on one worker.
- `false` keeps a group inside a parallel scope in order on one worker.
- Tests with a `beforeAll` or `afterAll` hook around them run in batches,
  at most as many as the target has workers, for each agent. Each batch
  runs in order on one worker and runs the hooks once, and again after
  a failed test. A serial group or a `parallel: false` group runs the hooks
  around it one more time.
- The repeats of a test (`--repeat-each`) run one after another on one
  worker, so the first records the replay cache and the rest replay it.
- With one worker the tests run one at a time, and not always in
  declaration order.
- The report lists the tests in declaration order.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | `true` inside a serial group, or inside a group or file with `parallel: false`. |
| `COLLECTION_ERROR` | `parallel` on a group with `serial: true`. |
| `COLLECTION_ERROR` | A value that is not a boolean. |

#### `sessions`

`test.setup` only. The session names the setup test must save.

```ts
test.setup('authenticate', { sessions: ['member', 'admin'] }, async ({ session }) => {});
```

A static, non-empty array of unique names. Each name matches
`/^[A-Za-z0-9_.-]{1,128}$/`. See [`test.setup`](#test-setup).

### Fixtures

Built-in fixtures are the fixtures a `test` has without `test.extend`: six
on every engine, and the ones the target's engine contributes. Each has a
scope on each engine.

| Built-in fixture | Type | Web | Mobile |
| --- | --- | --- | --- |
| [`agent`](https://e2e.com/docs/reference/agent) | `Agent` | test | test |
| [`app`](https://e2e.com/docs/reference/app) | `App` | test | worker |
| [`screen`](https://e2e.com/docs/reference/screen) | `Screen` | test | worker |
| `platform` | `string` | worker | worker |
| [`request`](https://e2e.com/docs/reference/request) | `APIRequest` | test | test |
| [`services`](#services) | `Record<string, unknown>` | worker | worker |
| [`session`](#test-setup) | `SetupSession` | test | test |
| [`browser`](https://e2e.com/docs/reference/web) | `Browser` | test | - |
| [`device`](https://e2e.com/docs/reference/mobile#device) | `Device` | - | worker |

The scope decides which code can use a built-in fixture:

- A test fixture belongs to one test attempt. Test bodies, `beforeEach`, and
  `afterEach` get it.
- A worker fixture outlives a test. `beforeAll`, `afterAll`, and
  [worker fixtures](#worker-fixtures) get it too.

An engine of your own sets the scope with
[`isolation`](https://e2e.com/docs/reference/engine#fixture-isolation).

`session` reaches only `test.setup` bodies. [`TestFixtures`](#testfixtures)
describes each core one. Every other fixture is one of
[your own](#your-own-fixtures).

An engine fixture is `undefined` on a target whose engine doesn't have it.
See [Engine fixtures across targets](#engine-fixtures-across-targets).

A test body, a hook, and a fixture function name the fixtures they use by
destructuring their first parameter: `async ({ app, screen }) => {}`. A
[`test.each`](#test-each) or
[`test.for`](#test-for) body names them in the parameter after its row.

| Throws | When |
| --- | --- |
| `COLLECTION_ERROR` | A test that runs on a target, or one of its hooks, names a fixture that isn't on any target in the config. No test runs. |
| `COLLECTION_ERROR` | A test body, a hook, or a fixture function takes the whole object (`async (fixtures) => {}`), a rest property (`{ app, ...rest }`), or a computed property, or is a bound function (`fn.bind()`), whose parameters cannot be read. |

<Note>
Built-in fixtures are lazy. Destructuring in the parameter list acquires
them before the body's first statement. [Your own
fixtures](#your-own-fixtures) are set up before the first `beforeEach`.
</Note>

#### `services`

Values yielded by the config's [`services`](https://e2e.com/docs/reference/config#services), keyed
by name. Each worker, `e2e mcp` session, or `openHost` host receives a copy of
the data. Each yielded function becomes an async function that calls the
original in the process that started the services (the runner, the `e2e mcp`
server, or the `openHost` host) and resolves to a copy of the result.

```ts

const test = base.extend<{}, {}, typeof config>();

test('signing up sends one welcome email', async ({ app, screen, services }) => {
  const inbox = await services.email.createInbox();

  await app.open('/');
  await screen.getByRole('textbox', { name: 'Email' }).fill(inbox.address);
  await screen.getByRole('button', { name: 'Sign up' }).click();

  const email = await services.email.waitForEmail(inbox.address, { subject: /welcome/i });

  expect(email.subject).toContain('Welcome');
  expect(await services.email.received(inbox.address)).toHaveLength(1);
});
```

All workers share one instance of each service, so a test can observe state
created by other tests.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | An argument is a function, a custom class instance, or another value that can't be copied. |
| The function's error | The function throws in the process that started the services. |
| `Error` | The return value is a function, a custom class instance, or another value that can't be copied. |

#### Your own fixtures

`test.extend(fixtures)` defines resources set up before each test that names
them and cleaned up afterward, including after a failure. In each fixture
function, code before `await use(value)` sets up the resource. The test
receives `value`, and code after `use` tears it down. For a guide with a full
suite, see [Writing fixtures](https://e2e.com/docs/fixtures).

```ts

export const test = base.extend<{ workspace: Workspace }>({
  workspace: async ({ browser }, use) => {
    const workspace = await createWorkspace();
    await signIn(browser, workspace);
    await use(workspace); // the hooks and the body run here
    await workspace.cleanup(); // teardown, after the body even when it failed
  },
});

test('renames the workspace', async ({ workspace, screen }) => {
  await screen.getByLabel('Name').fill(`${workspace.name} (renamed)`);
});
```

A fixture is set up on demand: for a test that names it, or that names a
fixture which names it. The fixtures a function names in its first parameter
are its dependencies:

- A definition sees the fixtures of the `test` it extends and the ones
  declared beside it in the same call, in any order. It does not see a
  fixture a later `extend` declares.
- A definition that needs no fixture takes `({}, use)`. ESLint's
  `no-empty-pattern` accepts it with `allowObjectPatternsAsParameters: true`.
- `[fn, { auto: true }]` sets a fixture up for every test of that `test`,
  named or not. Use it for a fixture that tests need and never read.

Per attempt:

1. The fixtures to set up are decided before anything runs: the ones the
   body and every `beforeEach` and `afterEach` hook that applies name, the
   ones those fixtures name, and the `auto` ones. A fixture nothing names
   does not run.
2. They run in declaration order, each after the fixtures it names, until
   each calls `use`. Setup counts against the test `timeout`. A failure is
   reported in phase `beforeEach`, before any `beforeEach` hook has run.
3. `beforeEach` hooks, the body, then `afterEach` hooks run with the same
   fixtures. Each receives the ones it names. The fixture set is the test's
   own chain: a hook that names
   `workspace` around a test registered through `base` fails with
   `COLLECTION_ERROR`.
4. Teardowns run in reverse order after the last `afterEach`, whether or not
   the body passed, each with its own `cleanupTimeout` budget. An error there
   fails a passing attempt in phase `afterEach` and joins `secondaryErrors`
   after a body failure.

A mistake that fails at collection is one run error with the file and line of
the code, and no test runs. A test that does not run on a target is not
checked against that target's fixtures.

| Mistake | Fails |
| --- | --- |
| A value that is not a plain object of functions or `[fn, { scope, auto }]` pairs, a scope other than `'test'` or `'worker'`, an `auto` that is not a boolean, an option other than `scope` and `auto`, or an empty name | At import, `COLLECTION_ERROR` naming the fixture |
| A function that does not destructure its first parameter, takes a rest or computed property there, or is a bound function | At import, `COLLECTION_ERROR` naming the fixture |
| Fixtures that name each other in a cycle | At import, `COLLECTION_ERROR` naming the cycle |
| A name that isn't a fixture on any target in the config, in a test that runs, its hooks, or a fixture they need | At collection, `COLLECTION_ERROR` |
| A `scope` or an `auto` that differs from that of the [fixture it extends](#extending-a-fixture) | At import when it is the same on every engine, otherwise at collection, `COLLECTION_ERROR` naming both |
| A fixture that names one a later `extend` declares | At collection, `COLLECTION_ERROR` |
| A definition that returns without calling `use` | The attempt, in `beforeEach`, `TEST_SETUP_FAILED` |
| A definition that calls `use` twice | The attempt, at teardown, `TEST_SETUP_FAILED` |
| A definition that throws before `use` | The attempt, in `beforeEach`, with that error. An `afterEach` hook that names the fixture is skipped. |
| A definition that throws after `use` | The attempt, in `afterEach`, with that error |

<Note>
A body or hook that hits the test `timeout` is abandoned, not cancelled, so
teardown starts while it may still be running. A setup abandoned this way
that reaches `use` later has `use` resolve at once, so its teardown code
runs detached from the run, where a throw goes unreported. Later fixtures,
hooks, and the test body do not start after an abandoned setup or hook
finishes. An app or device call it makes after its phase ended fails with
`CANCELLED`. Its other code, such as a Node `fetch`, still runs.
</Note>

#### Worker fixtures

A worker fixture has one instance per worker and target. Declare it as
`[fn, { scope: 'worker' }]` and type it with the second type argument of
`extend`:

```ts
export const test = base.extend<{}, { database: Database }>({
  database: [async ({}, use) => {
    const database = await startDatabase();
    await use(database);
    await database.stop();
  }, { scope: 'worker' }],
});
```

- Setup runs the first time a test or suite hook names it, or names a
  fixture that names it, inside that test's or hook's timeout. A failed setup
  fails that test or hook, and the next one sets the fixture up again.
- `[fn, { scope: 'worker', auto: true }]` sets it up for the first test or
  suite hook registered through its `test`, named or not.
- Teardown runs when the worker ends, before the engine is disposed, last set
  up first. Each teardown has `cleanupTimeout`. One that throws is a run error
  in phase `cleanup`.
- It sees worker fixtures only: the [built-in fixtures](#fixtures) whose
  scope is worker on the target, the worker fixtures of the `test` it extends,
  and the ones declared beside it. Naming a test fixture is
  `COLLECTION_ERROR`.
- On a mobile target its `device`, `app`, and `screen` act in the test or
  hook that is running when it calls them. Its teardown can still drive the
  device when the fixture names one of them.
- A worker keeps one instance of a worker fixture, also when the module
  that declares it is evaluated again: a test file after a failed test, or
  a module that declares tests or hooks. Only the fixture's value is kept,
  not the module's variables, so hand tests what they need through the
  value. On Bun, a worker fixture the test file
  declares gets a new instance each time the file is imported again, and
  the old one stays set up until the worker ends: declare it in a module
  the file imports.
- `extend({ ... })` without type arguments infers test fixtures only.

#### Engine fixtures across targets

On web, `device` is `undefined`, so a test with `device` can be run there too.
On web, the scope of `device` is:

- `worker` if `isolation: 'worker'` is set on every engine with the fixture.
- `test` otherwise.

The fixtures of every target are typed by the third type argument of
[`test.extend`](#test-extend):

```ts

export const test = base.extend<{}, {}, typeof config>();

test('signs out', async ({ app, platform, device }) => {
  if (platform === 'ios') {
    await device.clearKeychain();
  }

  await app.clearState();
});
```

- The fixtures are typed as a union with one member per target, told apart
  by `platform`. Each member has the fixtures of the target's engine. A
  fixture that only other targets have is typed as `undefined`.
- A target's engine fixtures, `app`, and `screen` are worker fixtures if
  `isolation: 'worker'` is set on its engine, and test fixtures otherwise.
- If a target's platform type is `string`, as on a target without an
  engine when `as const` isn't used on the config object, fixtures aren't
  narrowed by a `platform` check. Check the fixture instead
  (`device !== undefined`).
- With `platforms` on a test, its fixtures are typed for the targets that
  run it. With `platforms: ['ios']`, `device` is typed as `Device`. On a
  `describe`, `platforms` doesn't change the types.
- With a type annotation such as `const config: E2EConfig`, `typeof config` is
  plain `E2EConfig`. Calling `test.extend<{}, {}, typeof config>()` with that
  type fails with a type error because the target types aren't inferred.
  Use `as const satisfies E2EConfig` or `defineConfig` instead to keep the
  config's inferred type.

#### Extending a fixture

A definition named like a fixture the `test` already has extends that fixture.
It can be a [built-in fixture](#fixtures) or a fixture of an earlier `extend`.

```ts
export const test = base.extend({
  app: async ({ app }, use) => {
    await app.open('/dashboard');
    await use(app); // tests, hooks, and other fixtures get this value
  },
});
```

- Inside the function, its own name is the fixture it extends: the built-in,
  or the earlier fixture of that name. A function that does not name itself
  replaces the fixture.
- Tests, hooks, and other fixtures that name the fixture get the value passed
  to `use`. What the runner does with a built-in fixture does not change.
- Its scope and `auto` come from its options, like any other fixture. Without
  options, it's a test fixture that's set up for code that names it, even if
  the fixture it extends is a worker fixture or `auto`.
- To run a `device` override once per worker and use it in `beforeAll`,
  pass `{ scope: 'worker' }`. Like any worker fixture, it can't use test
  fixtures, so it fails on a target where the fixture it extends is a test
  fixture, such as `app` on web.
- It keeps the type. Define it with no type argument: the type arguments of
  `extend` are for new fixtures.
- If only some targets have the fixture, the function is still called on the
  other targets, with `undefined` under the fixture's name.
- In an `extend` call that also adds new fixtures, the override of a worker
  fixture is declared with `{ scope: 'worker' }`.
- With options, the override of a worker fixture is typed with worker
  fixtures only, whatever its scope. Without options it gets every fixture.

## Types

### `TestAPI`

```ts
export interface DescribeRegistrar<Options = DescribeOptions> {
  <Result>(title: string, body: SynchronousBody<Result>): void;
  <Result>(title: string, options: Options, body: SynchronousBody<Result>): void;
}

export interface DescribeAPI extends DescribeRegistrar {
  fail: DescribeRegistrar<Omit<DescribeOptions, 'fail'>>;
  configure(options: DescribeConfigureOptions): void;
  only: DescribeRegistrar<Omit<DescribeOptions, 'only'>>;
}

export interface TestRegistrar<Fixtures = TestFixtures & WorkerFixtures> {
  (title: string, fn: TestFn<Fixtures>): TestCase;
  <const Platform extends string = string>(
    title: string,
    options: TestOptions & { readonly platforms?: readonly Platform[] },
    fn: TestFn<SelectedFixtures<Fixtures, Platform>>,
  ): TestCase;
}

export interface EachRegistrar<Args extends readonly unknown[]> {
  (title: string, fn: EachFn<Args>): readonly TestCase[];
  (title: string, options: TestOptions, fn: EachFn<Args>): readonly TestCase[];
}

export interface TestAPI<Fixtures = TestFixtures, Worker = WorkerFixtures> extends TestRegistrar<Fixtures & Worker> {
  skip(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  skip(condition: boolean, reason?: string): void;
  skip(reason?: string): void;
  todo(title: string): TestCase;
  fixme(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  fixme(condition: boolean, reason?: string): void;
  fixme(reason?: string): void;
  skipIf<Condition>(condition: SynchronousCondition<Condition>): TestRegistrar<Fixtures & Worker>;
  runIf<Condition>(condition: SynchronousCondition<Condition>): TestRegistrar<Fixtures & Worker>;
  each<Row extends readonly unknown[] | [unknown]>(rows: readonly Row[]): EachRegistrar<[...Row, Fixtures & Worker]>;
  each<Row>(rows: readonly Row[]): EachRegistrar<EachArgs<Row, Fixtures & Worker>>;
  for<Row extends readonly unknown[] | [unknown]>(rows: readonly Row[]): EachRegistrar<[Row, Fixtures & Worker]>;
  for<Row>(rows: readonly Row[]): EachRegistrar<[Row, Fixtures & Worker]>;
  fail(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  fail(condition: boolean, reason?: string): void;
  fail(reason?: string): void;
  slow(condition: boolean, reason?: string): void;
  slow(reason?: string): void;
  setTimeout(timeout: number): void;
  step<T>(title: string, body: () => T | Promise<T>): Promise<T>;
  only(title: string, fn: TestFn<Fixtures & Worker>): TestCase;
  setup(title: string, options: SetupOptions, fn: SetupFn<Fixtures & Worker>): TestCase;
  extend<Extra = {}, ExtraWorker = {}, Config extends InferredConfig<Config> = {}>(): TestAPI<
    ConfigBase<Fixtures, Config> & Extra & ConfigFixtures<Config, 'test'>,
    ConfigBase<Worker, Config> & ExtraWorker & ConfigFixtures<Config, 'worker'>
  >;
  extend<const Overrides extends FixtureOverrides<Fixtures & Worker, Worker>>(
    overrides: Overrides,
  ): TestAPI<Fixtures & PickEach<Worker, TestOverrides<Overrides>>, OmitEach<Worker, TestOverrides<Overrides>>>;
  extend<Extra = {}, ExtraWorker = {}, Config extends InferredConfig<Config> = {}>(
    fixtures: FixtureDefinitions<
      ConfigBase<Fixtures, Config> & ConfigBase<Worker, Config> & ConfigFixtures<Config, 'test'> & ConfigFixtures<Config, 'worker'>,
      Extra,
      ConfigBase<Worker, Config> & ConfigFixtures<Config, 'worker'>,
      ExtraWorker
    >,
  ): TestAPI<
    ConfigBase<Fixtures, Config> & Extra & ConfigFixtures<Config, 'test'>,
    ConfigBase<Worker, Config> & ExtraWorker & ConfigFixtures<Config, 'worker'>
  >;
  describe: DescribeAPI;
  beforeEach(fn: TestHookFn<Fixtures & Worker>): void;
  afterEach(fn: TestHookFn<Fixtures & Worker>): void;
  beforeAll(fn: TestHookFn<Worker>): void;
  afterAll(fn: TestHookFn<Worker>): void;
}

export const test: TestAPI;
export const describe: TestAPI['describe'];
export const beforeEach: TestAPI['beforeEach'];
export const afterEach: TestAPI['afterEach'];
export const beforeAll: TestAPI['beforeAll'];
export const afterAll: TestAPI['afterAll'];
```

### `TestOptions`

```ts
export interface TestOptions {
  timeout?: number;
  retries?: number;
  tags?: readonly string[];
  skip?: boolean | string;
  fail?: boolean | string;
  only?: boolean;
  platforms?: readonly string[];
  session?: string;
  agentContext?: string;
  agent?: string | readonly string[];
  trace?: RecordingMode;
  video?: RecordingMode;
}

export interface DescribeOptions extends TestOptions {
  serial?: boolean;
  parallel?: boolean;
}

export interface DescribeConfigureOptions {
  parallel?: boolean;
}

export interface SetupOptions extends Omit<TestOptions, 'session' | 'only' | 'skip' | 'fail' | 'agent'> {
  sessions: readonly string[];
  agent?: string;
}
```

### `TestFixtures`

```ts
export interface TestFixtures {
  readonly agent: Agent;
  readonly app: App;
  readonly screen: Screen;
  readonly platform: string;
  readonly request: APIRequest;
  readonly services: Readonly<Record<string, unknown>>;
}

export interface SetupFixtures extends TestFixtures {
  readonly session: SetupSession;
}

export type FixtureScope = 'test' | 'worker';

export interface WorkerFixtures {
  readonly platform: string;
  readonly services: Readonly<Record<string, unknown>>;
}

export type SuiteFixtures = WorkerFixtures;
```

| Field | Description |
| --- | --- |
| `agent` | Agent steps. Acquiring the built-in agent without a configured model is `MODEL_UNAVAILABLE`. |
| `app` | App lifecycle: open, restart, clear state, back, screenshot, recording. |
| `screen` | Semantic queries and the actions on their matches. |
| `platform` | The target's platform label: `web`, `ios`, `android`, or an engine's own string. |
| `request` | HTTP calls, each one a step. A path resolves against the app URL. |
| `services` | See [`services`](#services). Sessions on one `openHost` host share the same copy. |

`SuiteFixtures` is deprecated: use `WorkerFixtures`.

### `FixtureDefinitions`

```ts
export type FixtureFn<Fixtures, Value> = (
  fixtures: Fixtures,
  use: (value: Value) => Promise<void>,
) => Promise<void>;

export type TestFixtureDefinition<Fixtures, Value> =
  | FixtureFn<Fixtures, Value>
  | readonly [FixtureFn<Fixtures, Value>, { readonly scope?: 'test'; readonly auto?: boolean }];
export type WorkerFixtureDefinition<Worker, Value> = readonly [
  FixtureFn<Worker, Value>,
  { readonly scope: 'worker'; readonly auto?: boolean },
];
export type FixtureDefinitions<Base, Extra, Worker = {}, ExtraWorker = {}> = {
  readonly [K in keyof Extra]: K extends keyof Base
    ? never
    : TestFixtureDefinition<Base & NoInfer<Extra> & NoInfer<ExtraWorker>, Extra[K]>;
} & {
  // Not inferred: an `extend({ ... })` without type arguments infers its test
  // fixtures from the definitions, as before worker fixtures; a worker
  // fixture is declared through the second type argument.
  readonly [K in keyof NoInfer<ExtraWorker>]: K extends keyof Base | keyof Extra
    ? never
    : WorkerFixtureDefinition<Worker & NoInfer<ExtraWorker>, NoInfer<ExtraWorker>[K]>;
} & {
  readonly [K in Extract<keyof Base, PropertyKey>]?: K extends keyof Worker
    ? WorkerFixtureDefinition<Worker & NoInfer<ExtraWorker>, Base[K]>
    : TestFixtureDefinition<Base & NoInfer<Extra> & NoInfer<ExtraWorker>, Base[K]>;
};
export type FixtureOverrides<Sees, WorkerSees, Base = Sees, Worker = WorkerSees> = {
  readonly [K in Extract<keyof Base, PropertyKey>]?: FixtureOverride<Base, Worker, K, Sees, WorkerSees>;
};
export type FixtureOverride<Base, Worker, K extends keyof Base, Sees, WorkerSees> = K extends keyof Worker
  ? FixtureFn<Sees, Base[K]> | readonly [FixtureFn<WorkerSees, Base[K]>, { readonly scope?: FixtureScope; readonly auto?: boolean }]
  : TestFixtureDefinition<Sees, Base[K]>;
export type TestOverrides<Overrides> = {
  [K in keyof Overrides]-?: Overrides[K] extends readonly [unknown, { readonly scope: 'worker' }] ? never : K;
}[keyof Overrides];
export type OmitEach<Worker, Names extends PropertyKey> = Worker extends unknown ? Omit<Worker, Names> : never;
export type PickEach<Worker, Names extends PropertyKey> = Worker extends unknown ? Pick<Worker, Extract<Names | 'platform', keyof Worker>> : never;
```

### Function types

```ts
export type TestFn<Fixtures = TestFixtures> = (fixtures: Fixtures) => void | Promise<void>;

export type SetupFn<Fixtures = TestFixtures> = (
  fixtures: Fixtures & SetupFixtures,
) => void | Promise<void>;

export type TestHookFn<Fixtures = TestFixtures> = (fixtures: Fixtures) => void | Promise<void>;

export type SuiteHookFn = TestHookFn<WorkerFixtures>;

export type SynchronousBody<Result> = Extract<Result, PromiseLike<unknown>> extends never
  ? () => Result
  : never;

export type EachArgs<Row, Fixtures> = [Row] extends [readonly unknown[]]
  ? [...Row, Fixtures]
  : unknown extends Row
    ? [...unknown[], Fixtures]
    : [Row, Fixtures];

export type EachFn<Args extends readonly unknown[]> = (...args: Args) => void | Promise<void>;

export type SynchronousCondition<Condition> = Extract<Condition, PromiseLike<unknown>> extends never
  ? Condition
  : never;

export interface TestCase {
  readonly [testCaseBrand]: true;
}
```

`SuiteHookFn` is deprecated: use `TestHookFn<WorkerFixtures>`.
