Skip to content
←Back to Blog
5 Tips for Writing Good Agentic Tests with e2e
AI CodingAgentic TestingEnd-to-End Testing

5 Tips for Writing Good Agentic Tests with e2e

Five practical rules for reliable agentic end-to-end tests: test user intent, wait for outcomes, assert independently, isolate state, and make failures diagnosable.

Kacper KapuściakNovember 13, 202610 min read13 views
ZH

A good end-to-end test suite is a lot like a well-maintained car. You can trust that it will not fail when you need it most. Nobody plans a road trip in a car they do not trust.

Tests work the same way. You need an end-to-end suite you can rely on. You make a change, the tests go green, and you have confidence that the flows you tested still work. That is the whole point.

Once the team stops trusting the suite, it starts to decay. A red build gets rerun instead of read. A failing test gets skipped "just for now." A few months later, nobody remembers what half of the tests even check.

Agentic testing uses AI agents to carry out user flows in your application. For automated UI testing, that means describing a critical business flow and letting an agent determine the interactions. You still decide what to assert and what counts as success.

This article presents five ways to write agentic end-to-end tests that are easier to maintain, using examples from e2e. The running example is a project-management application in which a user generates a monthly activity report.

Agentic testing best practices
Figure 1 | Agentic testing best practices. The agent can choose the interactions, but the engineer still defines the goal, the expected outcome, and the evidence that proves success.

Do not test the implementation

Your user wants to generate a monthly report. They do not care whether the date picker uses a Material UI component or how many nested elements sit inside the Generate button.

Tests tied to those details break when you change the implementation, even if the user can still complete the flow.

Most guides recommend stable, user-facing locators at this point. That is useful advice, but agentic testing lets us go further: define the test around the user's intention.

Users do not know what a test ID is. They do not even see it.

In the example, the test uses last month's report and sets up matching test data for each run. This keeps the suite useful as the calendar changes.

With agent.act, you describe a goal and let the agent work out the actions:

await agent.act("Generate last month's activity report");

The agent can determine whether it needs to select a month, enter two dates, or choose a preset. It does not need to know whether the app uses shadcn/ui, Bootstrap, or Material UI. Neither do your users.

Generating the report is only half of the test, however. You still need assertions proving that the report was generated and that its contents reflect the correct data. An empty report is a bug, and so is a report containing the wrong records.

await agent.assert(`The report shows ${expectedTasks.length} completed tasks`);
await agent.assert(
  `The report contains exactly these task records, with no additional tasks: ${JSON.stringify(expectedTasks)}`,
);

The report is now compared with actual activity data. An empty report fails when the source contains tasks. A matching count with the wrong records also fails, including records from another workspace. Read the expected data from the underlying activity source, independently of the report being tested.

Agentic tests also need a specific goal. A goal such as "Test reports" leaves too much room for interpretation. Generating a particular report gives the test a concrete outcome to check.

Reduce flaky tests by waiting for outcomes

Adding a five-second sleep is an easy way to make a flaky test pass on your machine. It is also an easy way to make every successful run five seconds slower. Those waits add up quickly.

Report generation is a good example. Depending on the amount of data and the current server load, the same operation may take a different amount of time on every run.

Instead of inserting an arbitrary delay, wait for the result:

await agent.waitFor("Last month's activity report is ready to view", {
  timeout: 15_000,
});

agent.waitFor checks a condition and waits for it to become true within both the timeout and the model-call budget. The timeout is a ceiling, not a mandatory delay. The test continues soon after the condition becomes true.

A useful waiting condition should mean that the next step is ready. Waiting for a loading spinner to disappear may appear to work, but it is a weak signal. Checking that the report itself is available gives the test much stronger evidence.

One API detail matters here: agent.assert checks the current screen immediately and does not wait. Use agent.waitFor whenever the application needs time to reach the state you want to inspect.

You can also use expect.poll to wait for a value. agent.waitFor uses an AI judge to determine whether the screen matches a description. By contrast, expect.poll repeatedly evaluates a deterministic matcher until it passes or reaches its timeout.

Make your assertions specific

Clicking Generate is an action. Getting a report with the right data is an outcome. A test that only performs actions leaves the most valuable part unchecked, so define the state that must be asserted.

Use the count from the API response or another source of truth as the expected value. Once the report is open, assert that result:

await agent.assert(
  `The report covers last month and shows ${expectedTasks.length} completed tasks`,
);

Precision matters. An assertion such as "The report looks correct" makes the agent guess what "correct" means.

With agent.assert, the judge evaluates fresh evidence from the current screen. A false or inconclusive judgment fails the test. It is not enough for the acting agent to claim that it completed the task.

Also consider how much each assertion proves. A "Report ready" message proves that the application reached that status, but it does not prove that the report contains the right information. Checking a preview does not prove that a downloaded CSV has the same contents.

For every meaningful action, identify the observable result that would convince you it worked. Put that check into the test.

Keep tests focused and independent

A report test should not depend on the "complete a task" test running first.

That dependency may appear to work while the whole suite runs in one particular order. Run the report test on its own, retry it, or run tests in parallel, and the required data may suddenly disappear.

Each test should arrange the state it needs. For the report example, that means a workspace with known tasks and completion dates. Another test completing a task in the same workspace should not change the data between the API read and report generation.

Good test-data management also includes cleanup. Use afterEach to clean up after each test, or afterAll for data that belongs to a whole suite. What goes in the hook depends on what the test created. If it created a workspace through the API, delete that workspace through the API. If it inserted records directly into the database, remove those records. The next test should receive the state it expects, without leftovers from a previous run.

e2e provides fixtures such as app, agent, and screen. You can define your own fixtures with test.extend, such as a workspace already populated with report data, and reuse them across test suites.

Sharing code is still useful when it keeps important behavior consistent. Use it where it makes tests easier to understand and maintain.

Make failures easy to debug

Finding a bug is useful. Receiving a red CI job that only says "something went wrong" is mostly an invitation to spend the afternoon investigating.

Start with a test name that describes the expected behavior. "Monthly activity report includes the workspace's completed tasks" provides much more context than "reports test." When it fails, the name should already identify which behavior broke.

Split generating a report, downloading it, and emailing it to a teammate into separate tests, each with its own setup and specific name. Within each test, keep agent goals small enough to check separately so that the debug log remains easy to follow.

The debug log should explain what failed and why: what the agent tried to do, what it expected, and what happened instead. A failed agent assertion can help. For example, it might report that the page shows the current month even though the test requested the previous month.

e2e's failure traces add the steps leading to the failure, application logs, recent agent turns, and a screenshot and screen snapshot when available. This gives both a human and a coding agent evidence to reason about.

A trace does not guarantee a perfect reproduction or identify the faulty line of application code. A clear goal, an explicit expectation, and the observed result still provide a much better starting point.

Pick one flow that your team currently tests by hand and write it in this style. When it fails, you should be able to tell what the user was trying to do, what happened instead, and where to begin looking.

A complete end-to-end example with e2e

If you have written tests before, you may recognize the Arrange, Act, Assert pattern. Set up the state, perform an action, and check the result. Agentic tests follow the same structure. You still decide where the test starts and what counts as success; the agent works out how to perform the action.

Here is the complete monthly-report test with all five practices applied:

test("Monthly activity report includes the workspace's completed tasks", async ({
  app,
  agent,
  reportWorkspace,
}) => {
  // Arrange
  const expectedTasks = await getCompletedTasks(reportWorkspace.id, "last month");
  await app.open(`/workspaces/${reportWorkspace.id}/reports`);

  // Act
  await agent.act("Generate last month's activity report");
  await agent.waitFor("Last month's activity report is open", { timeout: 15_000 });

  // Assert
  await agent.assert(
    `The report covers last month and shows ${expectedTasks.length} completed tasks`,
  );
  await agent.assert(
    `The report contains exactly these task records, with no additional tasks: ${JSON.stringify(expectedTasks)}`,
  );
});

Here, reportWorkspace is a fixture. getCompletedTasks reads the current workspace's activity through the application's API. The agent generates the report, waitFor waits for it to open, and the assertions compare its contents with the independent source of truth.

Where to go from here

A test suite earns trust one useful result at a time. Describe what the user wants to do. Wait for the application to be ready. Check that the result is actually what you expected. Agentic testing gives engineers more room to focus on those decisions, but it does not make the decisions for them.

Start with one test that the team keeps rerunning. Examine what it is trying to prove, what it waits for, and what would make it fail. Fix that test, then move to the next. Rewriting the entire suite is not a prerequisite for making it useful again.

To try the workflow in your own application, begin with the e2e quickstart, select one flow, and then break something on purpose to see whether the test catches it.

Source: 5 tips for writing good agentic tests with e2e, by Kacper Kapuściak, published November 13, 2026.

As an Amazon Associate, we earn from qualifying purchases.