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

# Core concepts

> Learn the three kinds of test steps in e2e (agent goals, AI assertions, and exact locators), when to use agentic or deterministic steps, and how to mix them in one test.

A test is built from three kinds of steps, and you choose how agentic it
is. An agent works out a goal's interactions and judges an assertion, and a
locator does exactly what you wrote.

| Step | API | Calls a model? |
| --- | --- | --- |
| [Goal](#goals) | `agent.act` | Yes, unless replayed from [cache](https://e2e.com/docs/cache) |
| [Assertion](#assertions) | `agent.assert`, `agent.waitFor`, `agent.extract` | Yes |
| [Locator](#locators) | `screen` and `expect` | No |

A test can be fully deterministic: written with locators only, it never
calls a model and needs no API key. It can also be fully agentic, or mix
both. Start with either and change one step at a time.

A deterministic test, with no model call:

```ts title="tests/add-todo.e2e.ts"

test('adds a todo', async ({ app, screen }) => {
  await app.open('/todos');
  await screen.getByLabel('New todo').fill('Buy milk');
  await screen.getByRole('button', 'Add').tap();

  await expect(screen.getByTestId('todo')).toHaveCount(1);
  await expect(screen.getByText('Buy milk')).toBeVisible();
});
```

The same app, with agent steps mixed in:

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

describe('todos', () => {
  test('the Done filter shows only completed todos', async ({ app, agent, screen }) => {
    await app.open('/todos');
    await agent.act('add todos "Buy milk" and "Walk the dog"');
    await agent.act('complete "Buy milk"');
    await agent.waitFor('"Buy milk" is completed and "Walk the dog" is open');

    await screen.getByRole('tab', 'Done').tap();

    await expect(screen.getByTestId('todo')).toHaveCount(1);
    await agent.assert('the only todo listed is "Buy milk"');
  });
});
```

Each test checks one behavior: set up the starting state, act toward one
goal, then assert the result. Always `await` every `agent`, `screen`, and
`expect.poll` call. If a test exits with a step still running, e2e fails it.

## Goals

`agent.act` takes a natural-language instruction, performs the interactions
needed to reach the goal, and throws if it can't. You describe what the user
wants, such as applying a discount code, and the agent works out which
controls to use:

```ts
await app.open('/checkout');
await agent.act('apply the discount code SUMMER');
```

Use a goal when UI changes keep forcing you to update selectors, or when a
flow takes many interactions but is easy to describe in plain English, such
as filling out and submitting a form. Move a button or redesign the form,
and the agent still carries out the intention with what's on screen. Goals
also let you monitor staging or production with real data, without seeding
it. Use a test account there, since the model sees what's on screen. See
[Security](https://e2e.com/docs/security).

Once a later check in the test passes, e2e records the actions and
[replays them](https://e2e.com/docs/cache) on the next run with no model call. When the UI
changes and a recording no longer matches, the agent
[steps in to adapt](https://e2e.com/docs/self-healing).

Start with one call for the behavior under test, and use the names shown on
screen. When the next step needs a known state,
[split the flow](https://e2e.com/docs/agent-steps#split-a-long-flow-into-goals).
Pass test data in `params`: a [`Secret`](https://e2e.com/docs/authentication) keeps a password
away from the model, and [`unique()`](https://e2e.com/docs/cache#what-must-match) lets a value
that changes on every run still replay.

## Assertions

An agent assertion judges the current screen on its own. The model doesn't
see earlier steps or `agent.act` summaries.

- **`agent.assert`** checks the screen right now and fails if the statement
  is false or there isn't enough evidence.
- **`agent.waitFor`** waits until a condition becomes true.
- **`agent.extract`** reads structured data from the screen into a schema,
  such as a Zod object.

Use one when several wordings or layouts would satisfy the same
requirement, such as a validation message that explains the problem
without matching one exact sentence:

```ts
await agent.assert('the error message explains that an email address is required');
```

Assert on meaning, and use a [locator](#locators) when exact wording
matters. For a chart or a layout, pass
[`vision: true`](https://e2e.com/docs/reference/agent#vision). [How agent steps work](https://e2e.com/docs/agent-steps)
covers what the model sees and what a step costs.

## Locators

Locators target known controls directly with no model call. Use `screen` and
`expect` when you know the exact interaction or the exact value to check:

```ts
await screen.getByLabel('Discount code').fill('SUMMER');
await screen.getByRole('button', 'Apply').tap();
await expect(screen.getByRole('status')).toHaveText('10% off');
```

Use locators for mechanics that are themselves under test, such as an empty
submission, a keyboard shortcut, or a drag offset, for sign-in setup tests,
and for projects that run without a model. Use `expect` when the result is
an exact value, count, or state, or when a message must use specific
wording.

Query by role and name first, label second, test ID last, so the test
refers to controls the user recognizes. An action or assertion on one
element fails when the locator matches several, so narrow it with
`.filter()`, `.first()`, or `.nth()`. `expect` retries until it passes or
times out. See the [screen reference](https://e2e.com/docs/reference/screen) and the
[expect reference](https://e2e.com/docs/reference/expect#locator-matchers), and the
[web reference](https://e2e.com/docs/reference/web) for routes, cookies, dialogs, and downloads.

## Combine them

Choose actions and assertions independently. Let the agent find its way
through a changing UI, then check an exact value with `expect`:

```ts
await agent.act('apply the discount code SUMMER');
await expect(screen.getByRole('status')).toHaveText('10% off');
```

Or fill and submit a form with locators, then use `agent.assert` to check
that its validation message explains the problem.

- **A goal adapts to what you wrote.** A vague instruction can allow a
  result you didn't intend. If a specific path matters, name it in the goal
  or use locators for those actions. An `expect` after `agent.act` catches a
  goal that passed the wrong way.
- **Model calls add latency, cost, and occasional mistakes.** The
  [replay cache](https://e2e.com/docs/cache) removes most of that for `agent.act`, while agent
  assertions always run live.

## Organize tests

Group tests with `describe`, and set `tags`, `retries`, or `timeout` on a
group or a test. The [test reference](https://e2e.com/docs/reference/test) shows all options.

- **Start near the screen you're testing.** Each test runs in its own
  attempt, so create data in a [fixture](https://e2e.com/docs/fixtures), restore a
  [saved session](https://e2e.com/docs/authentication), open a direct URL, or use a mobile
  [deep link](https://e2e.com/docs/mobile#the-device-fixture).
- **Share what repeats.** Use a `const` for a repeated locator, a hook or
  fixture for setup, and a [page object](https://e2e.com/docs/page-object-model) for a screen
  that several tests drive.
- **Chain dependent tests** with [`{ serial: true }`](https://e2e.com/docs/reference/test#serial)
  on a `describe`. They run in order on one worker and retry together.

## Next

<CardGroup cols={2}>
  <Card title="How agent steps work" icon="list-check" href="/agent-steps">
    Verdicts, exit codes, and what the model sees.
  </Card>
  <Card title="Self-healing tests" icon="bandage" href="/self-healing">
    See how an agent recovers when a recorded flow changes.
  </Card>
</CardGroup>
