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

# screen and Locator

> API reference for the screen fixture and Locator in e2e, with queries, refinement, actions, reads, and the match rules.

The `screen` fixture builds locators. A `Locator` stores a query and resolves
it when an action, read, or assertion runs. Every query also runs on a
locator, scoped to its subtree.

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

test('void an invoice', async ({ app, screen }) => {
  await app.open('/invoices');
  const row = screen.getByRole('listitem').filter({ hasText: 'Invoice 42' });
  await row.getByRole('button', 'Void').tap();
  await expect(row.getByText('Voided')).toBeVisible();
});
```

## Reference

### Queries

| Method | Returns |
| --- | --- |
| [`getByRole`](#getbyrole) | `Locator` |
| [`getByLabel`](#getbylabel) | `Locator` |
| [`getByPlaceholder`](#getbyplaceholder) | `Locator` |
| [`getByText`](#getbytext) | `Locator` |
| [`getByDisplayValue`](#getbydisplayvalue) | `Locator` |
| [`getByTestId`](#getbytestid) | `Locator` |

Every query returns a `Locator` synchronously and performs no work. An
option key the query does not take (`{ nam: 'Save' }`) throws
`INVALID_LOCATOR` naming the keys it does.

A string passed to `getByRole` as the name, `getByLabel`, `getByPlaceholder`,
`getByText`, or `getByDisplayValue` matches the whole text, case-sensitive,
after whitespace normalization: `getByRole('button', 'Save')` does not match
`Save changes`. `{ exact: false }` makes it a case-insensitive substring
match, and a `RegExp` matches as written.

Every query accepts `visible: true`; see
[Hidden duplicates](#hidden-duplicates).

#### `getByRole`

Matches nodes by [role](#types), optionally narrowed to an accessible name
and to states.

```ts
getByRole(role: Role | RoleAlias, options?: RoleOptions): Locator;
getByRole(role: Role | RoleAlias, name: TextMatch, options?: Omit<RoleOptions, 'name'>): Locator;
```

```ts
screen.getByRole('button', 'Save');
screen.getByRole('button', 'Save', { exact: false });
screen.getByRole('button', { name: 'Save', disabled: true }); // the object form
screen.getByRole('heading', /welcome/i, { level: 1 });
```

The accessible name goes second, a string or a `RegExp`, with the other
options after it. The object form, `{ name: 'Save' }`, is the same query.
The options are [`RoleOptions`](#types): `pressed` is the pressed state of
a toggle button, and `level` is a heading level, 1 through 6.
For visible content inside an unlabelled list item or status, filter by
text, for example `screen.getByRole('listitem').filter({ hasText: 'Invoice 42' })`.

<Note>
A role query never matches a node hidden from the accessibility tree: one
that does not render, or one under `aria-hidden`. On the other query kinds,
`visible: true` keeps only nodes that render, the same check `toBeVisible()`
makes, so an `aria-hidden` node that still paints counts as visible. See
[Hidden duplicates](#hidden-duplicates). On a device or a desktop app a role
query skips every node the engine marks hidden, which can include one
scrolled out of view: see [mobile](https://e2e.com/docs/reference/mobile#visibility) and
[desktop](https://e2e.com/docs/reference/desktop#visibility) for what each marks.
</Note>

##### `img` alias

`img` is an alias, not a role ([`RoleAlias`](#types)).
`getByRole('img', { name })` builds the same query as
`getByRole('image', { name })`. On the web, `image` covers `<img>` with alt text and any element
with `role="img"`. An `<img alt="">` is decoration and matches nothing,
unless it has a `title`, a `tabindex`, or a global ARIA attribute: then it is
an `image`.

##### Roles on the web

The web engine derives the roles from HTML the way HTML-AAM does:

- `<progress>` is `progressbar`, `<meter>` is `meter`, `<hr>` is `separator`.
- `<fieldset>` and `<details>` are `group`.
- `<input type="number">` is `spinbutton`. `<input type="file">` is `button`.
- `<select size="3">` is a `listbox`, like a `multiple` one. An
  `<input list>` naming a `<datalist>` is a `combobox`.
- A `<td>` of a `role="grid"` table is a `gridcell`.
- `<thead>` and `<tbody>` are `rowgroup`.
- `<th scope="row">` is `rowheader`. A scope-less `<th>` beside a data cell
  with text or children is also a `rowheader`; header-only rows keep
  `columnheader`. A lone scope-less header in a one-row table has no header
  role, but an explicit `scope="col"` or `scope="colgroup"` keeps
  `columnheader`.
- `<figure>` is `figure`, `<article>` is `article`.
- `<header>` and `<footer>` are `banner` and `contentinfo` only outside
  sectioning content or an element with a sectioning role (`article`,
  `complementary`, `main`, `navigation`, `region`).
- `<form>` and `<section>` are `form` and `region` only when they carry an
  `aria-label`, `aria-labelledby`, or `title`.
- `<menu>` is a `list`; only `role="menu"` is a `menu`.
- `role="presentation"` and `role="none"` are ignored on a focusable element
  or one with a global ARIA attribute such as `aria-label`:
  `<button role="none">` is still a `button`.

Names follow the same rules:

- A `<legend>`, `<figcaption>`, or `<caption>` names its fieldset, figure, or
  table.
- A role that accname names from content (a button, link, heading, tab, menu
  item, option, checkbox, radio, switch, cell, row or column header, row, tree
  item, tooltip) takes its name from its descendants, a custom element's
  shadow tree included. A
  descendant with a role of its own that is not text or structure (a `status`
  badge, a tree item's child `group`, an `img`) adds only its label or
  `title`: a tab holding `Inbox <span role="status">3</span>` is `Inbox`.
- An `<input type="submit">` or `type="reset"` with no `value` reads `Submit`
  or `Reset`.

##### Roles on a device

A device engine maps the platform types it has: a tab bar or segmented
control is a `tablist`, a progress indicator a `progressbar`, a stepper a
`spinbutton`. It keeps any other type verbatim, so a role with no native
widget, such as `tooltip` or `figure`, matches nothing on a phone.

##### Editing hosts

A `contenteditable` editing host, the root a TipTap, ProseMirror, Lexical, or
Slate editor renders into, is a `textbox`.

- Its value is its text as rendered. While it has focus, its `selection` is
  the text selected inside it. The value keeps spaces and newlines, so
  `toHaveValue` and `inputValue()` read a `white-space: pre-wrap` editor like
  a textarea.
- An empty editor reads as `''`: one holding only the `<p><br></p>` or the
  zero-width no-break space its editor pads an empty line with. That padding
  is never part of a value.
- It is named by its `aria-label`, `aria-placeholder`, or the
  `data-placeholder` its editor paints. The blocks inside it are content, not
  textboxes.
- The tag does not matter: an `<article contenteditable>` is the editor, not
  an article. A native control or a drawn surface made editable keeps its own
  role.
- A name from a block's `data-placeholder` (TipTap, ProseMirror) goes once
  the editor has content, as the painted hint does. From then on the host is
  an unnamed `textbox`. A name from the host's own `aria-label`,
  `aria-labelledby`, `aria-placeholder`, or `data-placeholder` (Quill) stays.

`getByRole` finds an editor only when the host carries
`role="textbox"`; `getByLabel` and `getByTestId` reach it either way. Anchor
a test on a label or a test id, not on the placeholder.

#### `getByLabel`

```ts
getByLabel(text: TextMatch, options?: TextMatchOptions): Locator;
```

```ts
await screen.getByLabel('Email').fill('ada@example.test');
```

#### `getByPlaceholder`

```ts
getByPlaceholder(text: TextMatch, options?: TextMatchOptions): Locator;
```

```ts
await screen.getByPlaceholder('Search memory...').fill('launch');
```

#### `getByText`

```ts
getByText(text: TextMatch, options?: TextMatchOptions): Locator;
```

```ts
screen.getByText('Welcome back', { exact: false });
```

On a device or a desktop app, `getByText` matches the text a node shows, not
its accessible name. A text that an app gives another accessible name (`5`
named `Words`, or an Android text with a content description) answers
`getByText('5')` and `getByLabel('Words')`, never `getByText('Words')`. Only a
node that shows no text, such as an icon button, matches by its accessible
name. In a browser `getByText` reads text content only.

What a text field shows depends on the platform:

| Platform | `getByText` finds a field by |
| --- | --- |
| Android | What it holds, or its hint while it is empty. Its content description answers `getByLabel`. |
| iOS | Its label, the one string iOS reports for it. |
| macOS | Its accessible name: a field has no text of its own. |

##### Echoed text

`getByText` answers with the innermost matching node, so a container that
echoes its child's text counts once, in a browser and on a device. Two
matches that
do not contain each other remain `LOCATOR_AMBIGUOUS`.

#### `getByDisplayValue`

Matches controls by their displayed value.

```ts
getByDisplayValue(value: TextMatch, options?: TextMatchOptions): Locator;
```

```ts
await screen.getByDisplayValue('ada@example.test').clear();
```

<Note>
In the web engine a `getByDisplayValue` locator cannot be the scope of a
child query or a `has` filter; both fail with `UNSUPPORTED_CAPABILITY`.
</Note>

#### `getByTestId`

Matches the node's `testId`.

```ts
getByTestId(id: TextMatch, options?: { visible?: boolean }): Locator;
```

```ts
screen.getByTestId('todo-3');
screen.getByTestId(/total-budgeted$/);
```

- On the web, `testId` is the value of the engine's test-id attribute
  (`web({ testIdAttribute })`, default `data-testid`).
- On a device, it is the accessibility identifier or resource id. For
  namespacing, see the mobile engine's
  [Android resource ids](https://e2e.com/docs/reference/mobile#capabilities).
- A string matches the whole id, case-sensitive; a `RegExp` tests it.
- `visible` is the only option.

#### Hidden duplicates

Every query accepts `visible: true`, which drops nodes the platform reports
as hidden before the exactly-one rule runs. Frameworks often keep a hidden
copy of content in the document, such as a closed drawer or an inactive tab
panel, and without `visible` both copies match.

```ts
await browser.reload();
// Two "No memories yet" nodes exist for a moment; one is display:none.
await expect(screen.getByText('No memories yet', { visible: true })).toBeVisible();
await screen.getByPlaceholder('Search memory...', { visible: true }).fill('launch');
await screen.getByTestId('memory-list', { visible: true }).getByRole('listitem').first().tap();
```

`visible` uses the same visibility check as `toBeVisible()`, `isVisible()`,
and `waitFor()`: what renders, as Playwright reads it.

- Hidden: `display: none`, `visibility: hidden`, a box with no size, a closed
  `<details>` body, shadow and slotted content included, and content under
  `content-visibility: hidden`.
- Not hidden: a closed `<details>` body the page's CSS shows through
  `::details-content`, and content under `content-visibility: hidden` set on an
  element whose box does not skip it (`display: contents`, an inline element,
  a table, a table row, ruby). An inline `<svg>`, `<button>`, or `<fieldset>`
  makes a box of its own, so content under one still reads hidden.
- Not hidden: `aria-hidden`, since a decorative spinner marked with it still
  paints, so `toBeHidden()` on one waits until it leaves.
- A child that sets `visibility: visible` under a hidden parent is visible.
- On the web, text directly under a `display: contents` element with
  `visibility: hidden` is hidden, where Playwright calls it visible.
- On the web, everything inside a hidden `<iframe>` is hidden, cross-origin
  frames included.
- It works with scopes, `filter`, `first`, `last`, and `nth`:
  `getByText('Save', { visible: true }).first()` is the first visible match.

Prefer it over `browser.locator('p:visible')`, which ties the test to CSS.

### Refinement

| Method | Returns |
| --- | --- |
| [`filter`](#filter) | `Locator` |
| [`or`](#or) | `Locator` |
| [`first`](#first) | `Locator` |
| [`last`](#last) | `Locator` |
| [`nth`](#nth) | `Locator` |

Refinement returns a new locator without querying the app.

#### `filter`

```ts
filter(options: { hasText?: TextMatch; hasNotText?: TextMatch; has?: Locator; hasNot?: Locator }): Locator;
```

```ts
const row = screen.getByRole('listitem').filter({ hasText: 'Invoice 42', hasNotText: 'Paid' });
await row.getByRole('button', 'Void').tap();
```

- `hasText` with a string is a case-insensitive substring match over the
  match and its descendants, unlike a query text, which matches exactly. Pass
  a `RegExp` for anything stricter. On a device or a desktop app it reads
  accessible names and values as well as text, so it keeps a node that
  `getByText` does not find by that string.
- `hasNotText` excludes matches with that subtree text, using the same
  substring or `RegExp` rules.
- `has` keeps a match whose subtree resolves the inner locator.
- `hasNot` drops a match whose subtree resolves the inner locator. It follows
  the same scoping rules as `has`.

| Throws | When |
| --- | --- |
| `INVALID_LOCATOR` | None of `hasText`, `hasNotText`, `has`, or `hasNot` is given. |
| `INVALID_LOCATOR` | Any other key, even beside them: `visible` is not a filter here. |
| `INVALID_LOCATOR` | `has` or `hasNot` is not a runner locator, or was made by another target's screen. |

#### `or`

```ts
or(other: Locator): Locator;
```

`a.or(b)` matches either branch once, in document order. It stays strict:
when both match different nodes, an action throws `LOCATOR_AMBIGUOUS`.
Add `first()` if either will do. Both locators must come from the same
screen and attempt. On web, both need identical literal frame-selector
chains; display-value branches cannot be composed.

| Throws | When |
| --- | --- |
| `INVALID_LOCATOR` | `other` is not a runner locator, or belongs to another screen or attempt. |
| `UNSUPPORTED_CAPABILITY` | Web branches have different frame-selector chains, or a branch is a display-value query. |

#### `first`

```ts
first(): Locator;
```

```ts
await screen.getByRole('listitem').first().tap();
```

#### `last`

```ts
last(): Locator;
```

```ts
await screen.getByRole('listitem').last().tap();
```

#### `nth`

```ts
nth(index: number): Locator;
```

```ts
await screen.getByRole('row').nth(2).getByRole('checkbox').check();
```

`index` is zero-based.

| Throws | When |
| --- | --- |
| `INVALID_LOCATOR` | A negative or non-integer index. |

### Screen actions

| Method | Returns |
| --- | --- |
| [`screen.tapAt`](#screen-tapat) | `Promise<void>` |
| [`screen.doubleTapAt`](#screen-doubletapat) | `Promise<void>` |
| [`screen.swipe`](#screen-swipe) | `Promise<void>` |
| [`screen.scrollUntilVisible`](#screen-scrolluntilvisible) | `Promise<void>` |
| [`screen.scrollTo`](#screen-scrollto) | `Promise<void>` |

`tapAt`, `doubleTapAt`, and `swipe` act on the viewport.

#### `screen.tapAt`

Use it for a pin on a canvas or a control the tree does not list.

```ts
tapAt(point: ScreenPoint, options?: ActionOptions): Promise<void>;
```

```ts
const map = (await screen.getByRole('image', 'Map').boundingBox())!;
await screen.tapAt({ x: map.x + 360, y: map.y + 70 });

await screen.tapAt({ x: '50%', y: '50%' });
```

- Each coordinate is CSS pixels from the viewport's top-left corner, the
  space `boundingBox()` reports in, or a
  percentage of the viewport from `'0%'` through `'100%'`, rounded to the
  nearest pixel (`'100%'` is the last one). They may mix: `{ x: '50%', y: 120 }`.
- Nothing is resolved or waited for; the page decides what the tap lands on.
- Uses `config.actionTimeout`.
- Prefer a locator when the tree lists the control, since a point moves with
  the layout. For a point inside a node, `tap({ position })` reads the node's
  box for you.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A negative or non-finite coordinate, or a string that is not a percentage from `'0%'` through `'100%'`. |
| `UNSUPPORTED_CAPABILITY` | The engine does not list `tap` in its pointer actions. |

<Note>
`tapAt` is not scoped: on a locator it still taps a viewport point.
</Note>

#### `screen.doubleTapAt`

Use it to double-tap a viewport point when the tree does not list the target.

```ts
doubleTapAt(point: ScreenPoint, options?: ActionOptions): Promise<void>;
```

```ts
await screen.doubleTapAt({ x: 120, y: 240 }, { timeout: 1_000 });
```

- Takes a `ScreenPoint`, pixels or percentages, as [`tapAt`](#screen-tapat) does.
- The page or device decides what receives the gesture. On web, this sends a primary-button double-click.
- On a device, this sends two presses at the point, as `doubleTap()` does on a node. See [Known device limitations](https://e2e.com/docs/mobile#known-device-limitations) for their timing on iOS.
- Defaults to `config.actionTimeout`.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A negative or non-finite coordinate, a string that is not a percentage from `'0%'` through `'100%'`, or an unknown option. |
| `UNSUPPORTED_CAPABILITY` | The engine does not list `doubleTap` in its pointer actions. |

<Note>
`doubleTapAt` is not scoped: on a locator it still double-taps a viewport point.
</Note>

#### `screen.swipe`

```ts
swipe(options: SwipeOptions | SwipePathOptions): Promise<void>;
```

```ts
await screen.swipe({ direction: 'up', momentum: 'fast' });

const row = (await screen.getByText('Design review').boundingBox())!;
await screen.swipe({
  from: { x: row.x + row.width - 10, y: row.y + row.height / 2 },
  to: { x: row.x + 10, y: row.y + row.height / 2 },
  duration: 300,
});

await screen.swipe({ from: { x: '50%', y: '80%' }, to: { x: '50%', y: '20%' } });
```

`{ direction, momentum? }` is a scroll gesture on the screen:

- `direction` is the way the content scrolls, not the finger: `'down'`
  reveals what is below.
- `momentum` is its fling strength, `'none'` by default. `'none'` is a
  plain drag of half the surface, `'slow'` a short fling, `'fast'` a long
  one. The engine decides how far each carries.

`{ from, to, duration? }` is a swipe along a path between two viewport
points: a touch swipe on a device, a pointer drag on a document platform.
Use it to reveal a row action, dismiss a sheet, or drag a card between
columns.

- `from` and `to` are `ScreenPoint`s, pixels or percentages, as
  [`tapAt`](#screen-tapat) takes.
- `duration` is how long the gesture takes, an integer from 16 through
  10000 ms. Omitted, it is the engine's default.

Uses `config.actionTimeout` and takes no `timeout` option.

| Throws | When |
| --- | --- |
| `ACTION_FAILED` | The gesture is rejected. |
| `INVALID_ARGUMENT` | A mix of the two shapes, an out-of-range duration, a coordinate off the plane or not a percentage from `'0%'` through `'100%'`, or a `timeout` key. |
| `UNSUPPORTED_CAPABILITY` | The engine does not list `swipe` in its actions (a direction) or `swipeTo` in its pointer actions (a path). |

#### `screen.scrollUntilVisible`

```ts
scrollUntilVisible(
  target: Locator,
  options?: { direction?: ScrollDirection; momentum?: Momentum; timeout?: number },
): Promise<void>;
```

```ts
await screen.scrollUntilVisible(screen.getByRole('button', 'Accept'));
await screen.getByTestId('feed').scrollUntilVisible(row);
```

| Option | Type | Default |
| --- | --- | --- |
| `target` | `Locator` | - |
| `options.direction` | `ScrollDirection` | `'down'` |
| `options.momentum` | `Momentum` | `'slow'` |
| `options.timeout` | `number` | `30000` |

- `momentum` is as [`screen.swipe`](#screen-swipe) defines it. A longer step
  is faster, but it must not carry the target past the surface unseen, as a
  virtualized list does.
- `timeout` is its own default, not `config.actionTimeout`. It bounds the
  whole scroll, each swipe included.
- On `screen` each step swipes the viewport. On a locator each step swipes
  that node. So a feed or a table that is its
  own scroll container pages without the pointer hovering it first.
- It stops at the first match that is not hidden. On a device, a node under
  the soft keyboard is hidden, so the scroll goes on
  ([Mobile visibility](https://e2e.com/docs/reference/mobile#visibility)).

| Throws | When |
| --- | --- |
| `INVALID_LOCATOR` | `target` is not a runner locator, or was made by another target's screen. |
| `INVALID_ARGUMENT` | An option it does not take. |
| `LOCATOR_NOT_FOUND` | The deadline expires first, a swipe it cut short included. |

#### `screen.scrollTo`

Scrolls to an edge of the page or a list, as far as it goes. Use it for
Cypress `cy.scrollTo('bottom')`, Detox `scrollTo('bottom')`, or Appium
`scrollToEnd()`.

```ts
scrollTo(edge: ScrollEdge, options?: ActionOptions): Promise<void>;
```

```ts
await screen.scrollTo('bottom');
await expect(screen.getByRole('contentinfo')).toBeInViewport();

await screen.getByTestId('feed').scrollTo('top', { timeout: 60_000 });
```

`edge` is `'top'`, `'bottom'`, `'left'`, or `'right'`. To scroll a list
inside the page, call it on the list: [`scrollTo`](#scrollto).

- On the web, `screen` scrolls the page. When the page itself does not
  scroll, as in an app shell, it scrolls the scroll container under the
  viewport's center; an iframe there is not entered, so call it on a locator
  inside the frame. `scroll-behavior: smooth` is skipped and no wheel event
  fires.
- On a device, it drags toward the edge from the middle of the container
  (the screen on `screen`) until a drag moves
  nothing. A spinner does not count as movement. A list of 45 screens takes
  about 22 s on an Android emulator and 50 s on an iOS simulator, so give a
  very long list a longer `timeout`.
- Content that grows when the end is reached is followed, but a slow load is
  not waited for. To reach a row a feed loads, use
  [`scrollUntilVisible`](#screen-scrolluntilvisible).
- On a device, a drag that lands on something that does not scroll moves
  nothing, so it reads as the edge.
- On a device, the last drag runs past the edge, so `scrollTo('top')` on a
  list with pull-to-refresh refreshes it. Content that changes on its own
  inside the container, such as a timer or an auto-advancing carousel, reads
  as movement and keeps it dragging until the timeout: call `scrollTo` on
  the list, not the screen.
- The timeout is [`config.actionTimeout`](https://e2e.com/docs/reference/config#actiontimeout).
  It bounds the whole scroll.
- On the web, it resolves at once when the container is already at the edge
  or nothing scrolls. On a device it still sends one drag to confirm, which
  can trigger pull-to-refresh.
- A frame's screen (`browser.frameLocator()`) refuses it. Call it on a
  locator inside the frame.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | An edge it does not know, an option other than `timeout`, or a frame's screen. |
| `ACTION_FAILED` | The edge was not reached before the timeout: `scrollTo('bottom') did not reach the edge within 30000ms (the content was still moving after 24 drags when the budget ran out)`. The parentheses hold the engine's reason. |
| `UNSUPPORTED_CAPABILITY` | The engine does not list `scrollTo` in its actions, as the desktop engine does not. |

### Screen reads

| Method | Returns |
| --- | --- |
| [`screen.tree`](#screen-tree) | `Promise<string>` |
| [`screen.debug`](#screen-debug) | `Promise<void>` |
| [`screen.pause`](#screen-pause) | `Promise<void>` |

`tree` and `debug` read the whole screen once, without waiting, and work on
every engine. They run as a step. A locator does not have them, and a frame
throws `INVALID_ARGUMENT`.

#### `screen.tree`

Returns the screen as the agent reads it. Use it to write a locator.

```ts
tree(options?: ActionOptions): Promise<string>;
```

```text
#n29 textbox "New todo"
#n30 button "Add"
 #n35 listitem "Milk Delete Milk" testid="todo"
  #n36 checkbox "Milk" [checked]
```

- One node per line, as `#id role "name" text="…" [states]`, with children
  indented and secrets redacted.
- Uses `config.actionTimeout`.
- The text has the same format and size limit as the trace's
  [screen at failure](https://e2e.com/docs/debugging#traces).

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | Called on a frame, or with an option it does not take. |

#### `screen.debug`

Prints [`screen.tree()`](#screen-tree) to the test's
[console output](https://e2e.com/docs/reference/reporters#console-output).

```ts
debug(options?: ActionOptions): Promise<void>;
```

```ts
await screen.debug();
```

#### `screen.pause`

The test is paused at this line, with the app open, until it is resumed.
You can use it in any `e2e run`, with or without
[`--step`](https://e2e.com/docs/reference/cli#step-mode).

```ts
pause(): Promise<void>;
```

```ts
await screen.pause();
```

In a terminal, the pause is shown under its test. Add `--headed` to look at
the browser while the test is paused.

```text
 ❯ |web| tests/checkout.e2e.ts 0/1
   └── pays with a card (k3f9)
       ⏸ paused  screen.pause()  tests/checkout.e2e.ts:5

 Test Files  0 passed (1)
      Tests  0 passed (1)

Paused (k3f9) at screen.pause()
  press enter to resume, press h to show help, press q to quit
```

Press Enter to resume the test, `h` to list the keys, or `q` to stop the run
with exit 130, as at a [`--step` prompt](https://e2e.com/docs/reference/cli#step-mode). Press `s`
for the screen or `l` for the app log, then use the viewer keys listed there.

Without a terminal, as in a coding agent's shell, the pause is printed with
the screen it waits on:

```text
Paused (k3f9) in pays with a card [web]:
  screen.pause() (tests/checkout.e2e.ts:5)
Screen:
  http://localhost:3000/checkout
  heading "Checkout"
Next: e2e run --step next to resume the test, or e2e run --step stop to end the run.
```

- To resume the test, run `e2e run --step next` from another shell in the
  same directory. To end the run with exit 130, run `e2e run --step stop`.
  You can use these commands with or without a terminal. At this pause, you
  can send `rest` in place of `next`.
- You get an answer once the test is paused again or the run ends. At the
  end, you get `The run has ended.` and the run's exit code.
  [Step commands](https://e2e.com/docs/reference/cli#step-commands) says what each answer holds.
- To [attach over MCP](https://e2e.com/docs/reference/mcp#attaching-to-a-held-test) from the
  same directory, pass the ID from the pause header, as in
  `open_session {attach: "k3f9"}`.
- A run without a terminal times out after 30 minutes with no command.
- With multiple workers, pauses queue one at a time while other workers
  continue.
- Only one run per directory can be controlled with `--step` commands at a
  time.
- The test is paused each time the line runs, on every attempt, retries and
  setup tests included.
- In a `--step` run, the test is still paused at `screen.pause()` after
  `n`, `a`, or `e2e run --step rest`.
- Paused time doesn't count toward any timeout.
- A test isn't paused in a session that an [MCP](https://e2e.com/docs/coding-agents#let-the-agent-use-the-app)
  `open_session {test}` opens, in a program on `@e2e-dev/core` or
  `openHost`, or in `run()` from `e2e/runner`. With `CI` set, the test still
  fails with `PAUSE_UNAVAILABLE` in `run()`, as in `e2e run`.
- In `e2e run --watch`, only the current run is cancelled when `q` is pressed
  at a pause or `e2e run --step stop` is run.
- A locator doesn't have it.

| Throws | When |
| --- | --- |
| `PAUSE_UNAVAILABLE` | `CI` is set. Remove the call before you commit, or run the test with `e2e run` in a terminal. A call where a pause isn't allowed fails with its error below instead. |
| `INVALID_ARGUMENT` | It is called on a locator or a frame, in an [`afterEach`](https://e2e.com/docs/reference/test#aftereach) hook, a fixture teardown, or unawaited code that runs after the body returned. Call it on `screen`, between steps in fixture setup, a `beforeEach` hook, or the test body. |
| `ACTION_FAILED` | It is called inside an agent step, such as an [`onAction`](https://e2e.com/docs/reference/agent#agent-act) hook or a [custom executor](https://e2e.com/docs/executors). The step fails with the pause's message, and the test isn't paused. In a [project tool](https://e2e.com/docs/tools) on the built-in agent, the refusal goes back to the model as a failed tool result and the step continues. Call it between steps instead. |
| `ASSERTION_FAILED` | It is called inside an [`expect.poll`](https://e2e.com/docs/reference/expect#polling-a-value) read. The read is retried until the poll times out. Call it outside the read. |
| `STEP_NOT_AWAITED` | The test body returns while a `screen.pause()` it did not await is still waiting. The test fails at the pause's line. Put `await` in front of the call. |
| `RUNNER_BUSY` | The run doesn't have a terminal, and another run in the directory is already controlled with `e2e run --step`. End that run with `e2e run --step stop`, or run this test in a terminal. Once the other run has ended, a test is paused at the next `screen.pause()` in this run. |

### Locator actions

| Method | Returns |
| --- | --- |
| [`tap`](#tap) | `Promise<void>` |
| [`click`](#tap) | `Promise<void>` |
| [`doubleTap`](#doubletap) | `Promise<void>` |
| [`dblclick`](#doubletap) | `Promise<void>` |
| [`secondaryTap`](#secondarytap) | `Promise<void>` |
| [`longPress`](#longpress) | `Promise<void>` |
| [`fill`](#fill) | `Promise<void>` |
| [`pressSequentially`](#presssequentially) | `Promise<void>` |
| [`clear`](#clear) | `Promise<void>` |
| [`press`](#press) | `Promise<void>` |
| [`check`](#check) | `Promise<void>` |
| [`uncheck`](#uncheck) | `Promise<void>` |
| [`selectOption`](#selectoption) | `Promise<void>` |
| [`focus`](#focus) | `Promise<void>` |
| [`blur`](#blur) | `Promise<void>` |
| [`hover`](#hover) | `Promise<void>` |
| [`setInputFiles`](#setinputfiles) | `Promise<void>` |
| [`dragTo`](#dragto) | `Promise<void>` |
| [`scrollIntoView`](#scrollintoview) | `Promise<void>` |
| [`swipe`](#swipe) | `Promise<void>` |
| [`scrollTo`](#scrollto) | `Promise<void>` |

Each action resolves one node, waits for actionability, and performs one
operation. The timeout is
[`config.actionTimeout`](https://e2e.com/docs/reference/config#actiontimeout), and every action
takes `{ timeout }`, in milliseconds, to override it: `0` waits until
the test timeout, or `cleanupTimeout` in `afterEach`. An
action takes only the options its signature names.

| Throws | When |
| --- | --- |
| `UNSUPPORTED_CAPABILITY` | The engine does not list the action's kind in `actions`; thrown before reaching the engine. |
| `INVALID_ARGUMENT` | An option key the action does not take, Playwright's `trial`, `force`, or `noWaitAfter` included, or a negative, `NaN`, or infinite `timeout`. Thrown before the node is resolved, so the control is never touched. |
| `LOCATOR_NOT_FOUND` | No match before the timeout. |
| `LOCATOR_AMBIGUOUS` | More than one match. |
| `ACTION_FAILED` | The action may already have committed; it is never repeated. |

#### `tap`

```ts
tap(options?: TapOptions): Promise<void>;
click(options?: TapOptions): Promise<void>;
```

```ts
await screen.getByRole('button', 'Save').tap({ timeout: 10_000 });
await screen.getByRole('image', 'Seat map').tap({ position: { x: 120, y: 48 } });
await row.click({ modifiers: ['Shift'] });
await screen.getByText('Shipping address').tap({ count: 3 });
```

`click` is an alias of `tap`. The options are [`TapOptions`](#types):

- `count`: how many taps in a row, a positive safe integer, default 1. In a
  browser the clicks arrive as one multi-click, so a triple click selects a
  paragraph. On a device they are `count` presses at the `doubleTap` cadence.
  `count: 2` is the same action as [`doubleTap()`](#doubletap). Three or more
  need an engine that lists the `multiTap` action; the browser and mobile
  engines both do.
- `modifiers`: keys held while the pointer clicks: `Shift`, `Control`,
  `Alt`, `Meta`, or `ControlOrMeta` (Control on Windows and Linux, Meta on
  macOS). The browser engine holds them.
- `position`: an offset from the node's top-left corner, inside its border,
  in CSS pixels. Without it the platform picks the point, usually the node's
  center. The engine scrolls the node into view when it lists
  `scrollIntoView`. The platform's other actionability checks (enabled, not
  covered) do not run.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | An unknown or repeated modifier, `modifiers` beside `position`, a `count` that is not a positive safe integer, or a `count` above 1 beside `position`. |
| `UNSUPPORTED_CAPABILITY` | `modifiers` on an engine that does not declare `tapModifiers`, the mobile engine among them; thrown before it acts. |
| `UNSUPPORTED_CAPABILITY` | A `count` of 3 or more on an engine without the `multiTap` action, or above the engine's limit (200 on the mobile engine); thrown before it acts. |
| `UNSUPPORTED_CAPABILITY` | `position` on an engine without the `tap` pointer action. |
| `ACTION_FAILED` | `position` on a node the browser engine cannot bring into view; its scroll waits for visibility. Other engines fail as they report it. |
| `LOCATOR_NOT_FOUND` | `position` on a node that resolves but never shows a visible box within the timeout. |

#### `doubleTap`

```ts
doubleTap(options?: ClickOptions): Promise<void>;
dblclick(options?: ClickOptions): Promise<void>;
```

```ts
await screen.getByRole('cell', 'Q3 budget').doubleTap();
```

`dblclick` is an alias of `doubleTap`. Takes `timeout` and `modifiers`, with the same rules and errors as
[`tap`](#tap).

#### `secondaryTap`

```ts
secondaryTap(options?: ClickOptions): Promise<void>;
```

```ts
await screen.getByRole('row', /Invoice 42/).secondaryTap();
```

A right click, or a two-finger tap. Takes `timeout` and `modifiers`, with the same rules and errors as
[`tap`](#tap).

#### `longPress`

```ts
longPress(options?: LongPressOptions): Promise<void>;
```

```ts
await screen.getByText('Design review').longPress({ duration: 800 });
```

- `duration` is the hold time, an integer from 100 through 10000 ms.
  Anything else is `INVALID_ARGUMENT`.
- Without it the engine's default applies: 500 ms on the browser engine, one
  second on the mobile engine.

#### `fill`

Replaces the input's current content.

```ts
fill(value: string | Secret, options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Email').fill('ada@example.test');
await screen.getByLabel('Password').fill(credentials.user('member').password);
```

A `Secret` is never logged, reported, or sent to a model.

<Note>
`fill` sets the value directly and fires no key events. An autocomplete, a
search-as-you-type box, or a masked input wired to `keydown` or `keyup`
never reacts to it. Use [`pressSequentially`](#presssequentially) for those.
</Note>

#### `pressSequentially`

Types through the engine's keyboard and appends to the current content.

```ts
pressSequentially(text: string, options?: PressSequentiallyOptions): Promise<void>;
```

```ts
await screen.getByLabel('City').pressSequentially('War', { delay: 50 });
```

- `delay` waits that many milliseconds between characters, each sent in its
  own keyboard call. Without it the whole text goes in one call.
- Focus, pauses, and keystrokes share the one action deadline: a pause is cut
  short at it and no character is sent past it.
- The step records the locator, not the text, like `fill`.

| Throws | When |
| --- | --- |
| `ACTION_FAILED` | The deadline passed mid-text; the error names how many characters landed. |
| `UNSUPPORTED_CAPABILITY` | The engine lacks the `focus` action or the `keyboard` capability; thrown before any node resolves. |
| `INVALID_ARGUMENT` | A `Secret` at runtime (a type error at compile time): a secret is filled, never typed as keystrokes. |

#### `clear`

```ts
clear(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Search').clear();
```

#### `press`

```ts
press(key: string, options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByRole('textbox', 'Search').press('Enter');
await screen.getByRole('textbox', 'Notes').press('ControlOrMeta+a');
```

A key is zero or more modifiers and one key, joined with `+`, as the
[key grammar](https://e2e.com/docs/reference/engine#keys) lists them. `Shift++` presses `+`.

On the web engine, a character that is not on a US keyboard (`é`, `中`) is
pressed in Chromium only. The page gets the same `keydown`, `input`, and
`keyup` as for any key, with an empty `code` and a `keyCode` of 0. Enter it
with [`fill`](#fill) or [`pressSequentially`](#presssequentially) in Firefox and
WebKit.

| Throws | When |
| --- | --- |
| `UNSUPPORTED_CAPABILITY` | A key the platform lacks. On the web engine, a character that is not on a US keyboard, in Firefox or WebKit. |

#### `check`

```ts
check(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByRole('checkbox', 'Remember me').check();
```

On the web engine, a checkbox or radio hidden under its own label (as in
Element Plus) is clicked through that label. Anything else on top of the
point the click lands on still fails `ACTION_FAILED`.

#### `uncheck`

```ts
uncheck(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByRole('checkbox', 'Remember me').uncheck();
```

| Throws | When |
| --- | --- |
| `ACTION_FAILED` | A checked native radio button, which only another radio in its group clears. |

#### `selectOption`

```ts
selectOption(value: SelectOption, options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Plan').selectOption('Pro');
await screen.getByLabel('Plan').selectOption({ label: 'Pro' });
await screen.getByLabel('Plan').selectOption({ value: 'pro' });
```

Pass a label string, or an object with exactly one of `label`, `value` (the
value attribute, which the form submits), or `index` (zero-based).

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | More than one option per call: an array, or an object with more than one of those keys. Also a negative or fractional `index`. Thrown before the engine acts. |

#### `focus`

```ts
focus(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Email').focus();
```

#### `blur`

```ts
blur(options?: ActionOptions): Promise<void>;
```

Web only. If the matched node already lacks focus, this has no effect.

```ts
await screen.getByLabel('Email').blur();
```

#### `hover`

```ts
hover(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByRole('button', 'Account').hover();
```

#### `setInputFiles`

```ts
setInputFiles(files: string | readonly string[] | FilePayload | readonly FilePayload[], options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByLabel('Receipt').setInputFiles('fixtures/receipt.pdf');
await screen.getByLabel('Receipt').setInputFiles({
  name: 'receipt.txt', mimeType: 'text/plain', buffer: Buffer.from('Receipt total: 12.00'),
});
await screen.getByLabel('Receipt').setInputFiles([]);
```

Web only. A path resolves from the project root. Pass a plain object with only the fields of `FilePayload`: `name: string`, `mimeType: string`, and `buffer: Buffer`. Pass one payload or an array of payloads; do not mix paths and payloads in an array. The combined payload size must be less than 50 MiB. For larger files, use a path if the target supports transferring files of that size. An empty array clears the input and fires `input` and `change`. A button that opens a file chooser accepts the same inputs.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A blank or missing path, a path under a directory the runner cannot search, an invalid payload, mixed paths and payloads, or payloads totaling 50 MiB or more. |
| `UNSUPPORTED_CAPABILITY` | On a device, or for payloads on an engine that does not declare `setInputFilePayloads`. |
| `ACTION_FAILED` | A button that opens no file chooser. |

#### `dragTo`

```ts
dragTo(target: Locator, options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByText('Design review').dragTo(screen.getByRole('region', 'Done'));
```

| Throws | When |
| --- | --- |
| `INVALID_LOCATOR` | `target` is not a runner locator, or was made by another target's screen. |

#### `scrollIntoView`

```ts
scrollIntoView(options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByRole('contentinfo').scrollIntoView();
```

#### `swipe`

```ts
swipe(options: SwipeOptions & ActionOptions): Promise<void>;
```

```ts
await screen.getByTestId('feed').swipe({ direction: 'down', momentum: 'slow' });
```

It takes `{ direction, momentum? }` as [`screen.swipe`](#screen-swipe)
defines them, plus `timeout`, which `screen.swipe` refuses. It has no
`{ from, to }` form.

#### `scrollTo`

```ts
scrollTo(edge: ScrollEdge, options?: ActionOptions): Promise<void>;
```

```ts
await screen.getByTestId('feed').scrollTo('bottom');
await screen.getByRole('list', 'Photos').scrollTo('right');
```

Scrolls the node, or its nearest ancestor that scrolls along the edge's
axis, to an edge. On a device it drags inside the node's box, so locate the
list itself, not a row. The rest is as [`screen.scrollTo`](#screen-scrollto) describes.

### Locator reads

| Method | Returns |
| --- | --- |
| [`textContent`](#textcontent) | `Promise<string \| null>` |
| [`inputValue`](#inputvalue) | `Promise<string>` |
| [`getAttribute`](#getattribute) | `Promise<string \| null>` |
| [`isVisible`](#isvisible) | `Promise<boolean>` |
| [`isHidden`](#ishidden) | `Promise<boolean>` |
| [`isEnabled`](#isenabled) | `Promise<boolean>` |
| [`isDisabled`](#isdisabled) | `Promise<boolean>` |
| [`isChecked`](#ischecked) | `Promise<boolean>` |
| [`boundingBox`](#boundingbox) | `Promise<{ x, y, width, height } \| null>` |
| [`screenshot`](#screenshot) | `Promise<string>` |
| [`count`](#count) | `Promise<number>` |
| [`all`](#all) | `Promise<Locator[]>` |
| [`allTextContents`](#alltextcontents) | `Promise<string[]>` |
| [`waitFor`](#waitfor) | `Promise<void>` |

Reads follow the [Match rules](#match-rules). `count`, `all`, and
`allTextContents` take a snapshot and do not wait.

On a secure field, `textContent`, `inputValue`, `getAttribute`, and
`allTextContents` throw `POLICY_DENIED`, as the matching
[`expect` matchers](https://e2e.com/docs/reference/expect#secure-fields) do. `isEnabled`,
`isDisabled`, `isChecked`, and `boundingBox` are allowed there, and
`screenshot` masks the field.

#### `textContent`

Reads the node's rendered text with whitespace collapsed to single spaces.

```ts
textContent(): Promise<string | null>;
```

```ts
const message = await screen.getByRole('alert').textContent();
```

- On the web that is what `innerText` reads, not the DOM's `textContent`:
  CSS `text-transform` applies, `display: none` descendants are left out, and
  a `<br>` reads as a space.
- A node that is not rendered itself, such as a `display: none` one, reads
  its DOM text, as `innerText` does.

#### `inputValue`

```ts
inputValue(): Promise<string>;
```

```ts
const email = await screen.getByLabel('Email').inputValue();
```

On a checkbox or radio, `inputValue()` and `toHaveValue` read its value
attribute, `on` when it has none, whatever its checked state. `isChecked()`
reads the state.

`inputValue()` reads a range widget as
[`toHaveValue`](https://e2e.com/docs/reference/expect#tohavevalue) does. Playwright's
`inputValue()` throws on an ARIA widget.

| Throws | When |
| --- | --- |
| `ACTION_FAILED` | A node with no value, such as a heading or a button. A field with no value reads `""`. |

#### `getAttribute`

```ts
getAttribute(name: string): Promise<string | null>;
```

```ts
const href = await screen.getByRole('link', 'Docs').getAttribute('href');
```

On a device, a node carries up to five attributes:

- `label`: the accessibility label. On iOS, that is the device's own label, so
  an empty field whose placeholder was folded out keeps its full label. On
  Android, it is the content description, or the node's text when there is no
  description. An empty Android field showing only its hint has no `label`, and
  neither does an empty Android field whose content description equals its hint.
- `resource-id`: the node's test id, which is the Android resource id or the
  iOS accessibility identifier (what Appium reads as `name`).
- `class`: the Android class name, or the iOS element type without the
  `XCUIElementType` prefix, such as `TextField` (what Appium reads as `type`).
- `content-desc`: Android only. Missing when the content description equals the
  visible text or hint.
- `placeholder`: present when the platform reports a hint or placeholder.

On an iOS device cloud that serves an Appium page source, both values fall
back to Appium's `name`. `name` is the identifier, or the label
when an element has no identifier. So `resource-id` and `label` can each return
the other's value there: an element with a test id and no label reads its test
id as `label`. For the text a field holds, use `inputValue()`.

On macOS (`@e2e-dev/desktop`), a node carries `label` (a control's
accessible name, up to 1,000 characters; text has none, since `textContent`
reads it), `identifier`
(the developer's accessibility identifier, also its test id), `description`
(left out when it is the accessible name, which `label` reads, as an AppKit
field's description often is), `placeholder`, and `hint` (its help text), each
when the app reports it. On a
password field, `getAttribute` throws `POLICY_DENIED`, as it does on every
engine.

#### `isVisible`

```ts
isVisible(): Promise<boolean>;
```

```ts
const open = await screen.getByRole('dialog').isVisible();
```

- `false` for zero matches, and for a `frameLocator` whose frame is not in
  the document.
- Uses the same visibility check as `visible: true` (see
  [Hidden duplicates](#hidden-duplicates)).

| Throws | When |
| --- | --- |
| `LOCATOR_AMBIGUOUS` | Several matches. |

#### `isHidden`

```ts
isHidden(): Promise<boolean>;
```

```ts
const gone = await screen.getByTestId('spinner').isHidden();
```

It has the same strictness as `isVisible`: `true` for zero matches.

| Throws | When |
| --- | --- |
| `LOCATOR_AMBIGUOUS` | Several matches. |

#### `isEnabled`

```ts
isEnabled(): Promise<boolean>;
```

```ts
const ready = await screen.getByRole('button', 'Pay').isEnabled();
```

#### `isDisabled`

```ts
isDisabled(): Promise<boolean>;
```

```ts
const blocked = await screen.getByRole('button', 'Pay').isDisabled();
```

It has the same strictness as `isEnabled`.

| Throws | When |
| --- | --- |
| `LOCATOR_NOT_FOUND` | Zero matches. |
| `LOCATOR_AMBIGUOUS` | Several matches. |

#### `isChecked`

```ts
isChecked(): Promise<boolean>;
```

```ts
const remembered = await screen.getByRole('checkbox', 'Remember me').isChecked();
```

A checkable role with no state reported, such as an ARIA switch without
`aria-checked`, reads `false`.

| Throws | When |
| --- | --- |
| `ACTION_FAILED` | A node with no checked state, such as a button or a heading. |

#### `boundingBox`

```ts
boundingBox(): Promise<{ x: number; y: number; width: number; height: number } | null>;
```

```ts
const map = (await screen.getByRole('image', 'Map').boundingBox())!;
```

The box is relative to the viewport, in CSS pixels, and on a device in points (physical pixels on
Android). It is `null` for a node that lays out no box
(`display: none` on it or an ancestor). A `visibility: hidden` node keeps
its box.

#### `screenshot`

```ts
screenshot(label?: string): Promise<string>;
```

```ts
const card = await screen.getByTestId('order-summary').screenshot('summary');
```

- The file is what [`app.screenshot`](https://e2e.com/docs/reference/app#screenshot) saves, cut
  to the match's box: an attempt artifact under `screenshots/`, with the
  same masking and the same pixel density.
- `label` joins the step's name and the file name.
- It returns the file's absolute path.
- The match is scrolled into view first. One larger than the viewport keeps
  the part inside it.
- It waits until the match is visible, and its box and the viewport hold
  still across the capture. A match the page moves out of the viewport is
  scrolled back.

| Throws | When |
| --- | --- |
| `INVALID_ARGUMENT` | A `label` that is not a string. |
| `LOCATOR_NOT_FOUND` | No visible match within the action timeout, one that kept moving, or one outside the viewport on an engine that cannot scroll to it. |
| `LOCATOR_AMBIGUOUS` | More than one match. |
| `ACTION_FAILED`, `ENGINE_FAILURE` | The scroll or the capture failed or timed out, as on a web match that never stops animating. |
| `UNSUPPORTED_CAPABILITY` | The engine takes no screenshots, or writes one that is not a PNG. |
| `POLICY_DENIED` | On iOS and Android, a secure field on screen has no bounds to mask. |

#### `count`

```ts
count(): Promise<number>;
```

```ts
const rows = await screen.getByRole('row').count();
```

`0` for zero matches, and for a `frameLocator` whose frame is not in the
document.

#### `all`

Resolves the query once, so a loop can act on each row.

```ts
all(): Promise<Locator[]>;
```

```ts
for (const row of await screen.getByRole('row').all()) {
  await row.getByRole('checkbox').check();
}
```

- It neither waits nor enforces exactly-one: zero matches is an empty array,
  the same snapshot rule as `count()`. A `frameLocator` whose frame is not in
  the document counts as zero matches here, where an action or assertion
  polls for it.
- Each locator that `all()` returns re-resolves when used. A list that changes
  under the loop can make a later `nth(i)` point at a different row, or at
  nothing. Follow the loop with an assertion on the list.

#### `allTextContents`

```ts
allTextContents(): Promise<string[]>;
```

```ts
expect(await screen.getByRole('listitem').allTextContents()).toEqual(['Alpha', 'Beta']);
```

- Text reads as in [`textContent`](#textcontent).
- It neither waits nor enforces exactly-one: zero matches is an empty array,
  as for [`all`](#all).
- To check the texts, use
  [`toHaveText([...])`](https://e2e.com/docs/reference/expect#locator-matchers) instead of a
  loop.

#### `waitFor`

```ts
waitFor(options?: { state?: 'attached' | 'detached' | 'visible' | 'hidden'; timeout?: number }): Promise<void>;
```

```ts
await screen.getByTestId('spinner').waitFor({ state: 'hidden' }); // default state: 'visible'
```

| State | Waits for |
| --- | --- |
| `'visible'` (default) | One visible match. |
| `'attached'` | One match, hidden or shown. |
| `'detached'` | No match. |
| `'hidden'` | A hidden match, or none. |

`timeout` defaults to `config.actionTimeout`.

| Throws | When |
| --- | --- |
| `LOCATOR_NOT_FOUND` | The timeout expires. |
| `LOCATOR_AMBIGUOUS` | Several matches, in every state. |
| `INVALID_ARGUMENT` | Any other state, or an option key besides `state` and `timeout`; thrown before anything is resolved. |

## Match rules

Most operations require exactly one match. A read polls for its one match
until the action timeout, as an action does. Then it returns the current
value without waiting for it to change. Use [`expect`](https://e2e.com/docs/reference/expect) to
wait for a value.

A node the engine reports stale is re-resolved within the same timeout:
a resolve that raced a navigation, or a match the app replaced while it was
read.

| Operation | Zero matches | Multiple matches |
| --- | --- | --- |
| Actions | Poll until the timeout, then `LOCATOR_NOT_FOUND` | `LOCATOR_AMBIGUOUS` |
| Reads | Poll until the timeout, then `LOCATOR_NOT_FOUND` | `LOCATOR_AMBIGUOUS` |
| `count()`, `all()`, `allTextContents()` | `0`, `[]`, `[]` | The count, one locator per match, one text per match |
| `isVisible()`, `isHidden()` | `false`, `true` | `LOCATOR_AMBIGUOUS` |
| Assertions | Poll until the timeout, then `ASSERTION_FAILED` | `LOCATOR_AMBIGUOUS` |
| Any of these under a frame that is not in the document | As zero matches for `count()`, `all()`, `allTextContents()`, `isVisible()`, and `isHidden()`; actions and reads poll for the frame until the timeout, then `LOCATOR_NOT_FOUND`; assertions, then `ASSERTION_FAILED` | `LOCATOR_AMBIGUOUS` when several frames match |

## Types

```ts
export type Role =
  | 'button'
  | 'link'
  | 'textbox'
  | 'searchbox'
  | 'combobox'
  | 'listbox'
  | 'option'
  | 'checkbox'
  | 'radio'
  | 'radiogroup'
  | 'switch'
  | 'slider'
  | 'spinbutton'
  | 'progressbar'
  | 'meter'
  | 'image'
  | 'heading'
  | 'tab'
  | 'tablist'
  | 'tabpanel'
  | 'menu'
  | 'menubar'
  | 'menuitem'
  | 'menuitemcheckbox'
  | 'menuitemradio'
  | 'toolbar'
  | 'tooltip'
  | 'tree'
  | 'treeitem'
  | 'list'
  | 'listitem'
  | 'table'
  | 'grid'
  | 'row'
  | 'rowgroup'
  | 'rowheader'
  | 'cell'
  | 'gridcell'
  | 'columnheader'
  | 'separator'
  | 'group'
  | 'article'
  | 'figure'
  | 'form'
  | 'status'
  | 'alert'
  | 'dialog'
  | 'alertdialog'
  | 'main'
  | 'navigation'
  | 'banner'
  | 'contentinfo'
  | 'complementary'
  | 'region';

export type RoleAlias = 'img';

export type TextMatch = string | RegExp;

export interface TextMatchOptions {
  exact?: boolean;
  visible?: boolean;
}

export interface RoleOptions extends TextMatchOptions {
  name?: TextMatch;
  checked?: boolean;
  disabled?: boolean;
  selected?: boolean;
  expanded?: boolean;
  pressed?: boolean;
  level?: number;
}

export interface ActionOptions {
  timeout?: number;
}

export interface LongPressOptions extends ActionOptions {
  duration?: number;
}

export interface PressSequentiallyOptions extends ActionOptions {
  delay?: number;
}

export interface SwipeOptions {
  direction: ScrollDirection;
  momentum?: Momentum;
  from?: never;
  to?: never;
  duration?: never;
}

export interface SwipePathOptions {
  from: ScreenPoint;
  to: ScreenPoint;
  duration?: number;
  direction?: never;
  momentum?: never;
}

export type Point = ViewportPoint; // { x: number; y: number }

export type ScreenCoordinate = number | `${number}%`;

export interface ScreenPoint {
  readonly x: ScreenCoordinate;
  readonly y: ScreenCoordinate;
}

export interface ClickOptions extends ActionOptions {
  modifiers?: readonly KeyModifier[];
}

export type KeyModifier = 'Shift' | 'Control' | 'Alt' | 'Meta' | 'ControlOrMeta';

export interface TapOptions extends ClickOptions {
  position?: Point;
  count?: number;
}

export type SelectOption =
  | string
  | { label: string; value?: never; index?: never }
  | { value: string; label?: never; index?: never }
  | { index: number; label?: never; value?: never };

export type ScrollDirection = 'up' | 'down' | 'left' | 'right';

export type ScrollEdge = 'top' | 'bottom' | 'left' | 'right';

export type Momentum = 'none' | 'slow' | 'fast';
```

## Related

[`expect`](https://e2e.com/docs/reference/expect) waits for a locator's state. The
[`browser`](https://e2e.com/docs/reference/web) fixture adds CSS locators and frames.
