Make agent UI tests prove the result
A passing button-state check can miss a broken filter. A real browser comparison shows how to give an AI-assisted UI fix an acceptance test that detects the original failure.

A coding agent changes a filter, adds a test, and reports that the check passes. Before approving the work, ask what the test actually proves. A selected button can be correct while the list beneath it is wrong. The useful acceptance condition describes the result a reader needs: turn on “Saved only” and see only the saved notes.
This matters when an assistant can edit both the implementation and its tests. Playwright’s current agent documentation separates planning, test generation and test repair into three roles. Those capabilities make the intended outcome worth writing down before the repair begins. Our recommendation is to keep that outcome fixed while reviewing changes to either file. Read the Playwright Test Agents guide.
Write the result before asking for the fix
Our shelf contains two notes. “Spacing systems” is saved; “Color studies” is not. Both appear initially. The toggle has a stable accessible name, “Saved only,” and communicates its selected state with aria-pressed. In the broken variant, activating it updates the button and status message but leaves both records visible. The corrected variant also filters the records.
Actual Chromium capture at a 390 px viewport, rendered at 2× pixel density. The outline marks keyboard focus. Read the lower card: the selected filter has not removed the unsaved note.The test brief can be one sentence: “Starting with these two records, activate Saved only; Spacing systems remains, Color studies disappears, and switching the filter off restores both.” That sentence gives a reviewer a starting state, an action, an exact result and a way back. It also prevents an empty list from satisfying the requirement merely because the unsaved card vanished.
This follows Playwright’s guidance to test behavior that users can observe and to keep each test’s state isolated. For an agent handoff, include the small data fixture and route alongside the sentence. A fresh page with known records is more reproducible than an existing browser tab whose filters or storage may already have changed. See the testing guidance.
Make the same assertion face both versions
We first check aria-pressed after keyboard activation. It equals true in both implementations, so that check confirms the control state but cannot detect this bug. We then compare the complete ordered set of headings inside the reading list with the expected single title. That assertion fails in the broken variant and passes in the corrected one.
Observed after the same Saved only action| Check | Broken variant | Corrected variant |
|---|
| Button reports aria-pressed=true | Pass | Pass |
| List titles equal [Spacing systems] | Fail: includes Color studies | Pass: only Spacing systems |
| Switch off; both titles return | Pass | Pass |
The corrected variant after the same key action and at the same viewport. The button looks selected in both captures; the missing unsaved card is the meaningful change.All twelve combinations reproduced the expected result: two variants, two viewport widths of 900 and 390 pixels, and three browsers. The tested builds were Chromium 153.0.8010.12, Firefox 155.0 and WebKit 26.6, using Playwright 1.63.0. The stronger assertion failed in all six broken cases and passed in all six corrected cases. These are fixture observations, not model-success rates, speed measurements or a claim about the newest browser releases.
Assert the content the control is meant to change
Use a locator for the named button, then scope the content expectation to the named list. Role and accessible-name locators make the action readable and avoid tying the test to decorative class names. They also keep another heading elsewhere on the page from accidentally satisfying the expectation. Read the locator guidance.
// After opening the fixture with its two known notes:
const filter = page.getByRole('button', {
name: 'Saved only', exact: true
});
const titles = page
.getByRole('list', { name: 'Reading shelf' })
.getByRole('heading');
await expect(titles).toHaveText([
'Spacing systems', 'Color studies'
]);
await filter.focus();
await page.keyboard.press('Enter');
await expect(filter).toHaveAttribute(
'aria-pressed', 'true'
);
await expect(titles).toHaveText(['Spacing systems']);
await page.keyboard.press('Enter');
await expect(titles).toHaveText([
'Spacing systems', 'Color studies'
]);
The excerpt uses the same locators and expected titles as the retained experiment. Playwright’s awaited web assertions retry until their condition is met or their timeout is reached. Keep that waiting behavior instead of reading a value once immediately after an asynchronous update. In a real network-backed filter, also define the loading, failure and retry behavior; this local fixture does not exercise those paths. Read the assertion reference.
Keep visual review beside the behavioral test
Two kinds of evidence for the same change
Outcome assertion
Checks the agreed content result.
- Detects the extra unsaved record in this example.
- Checks that the saved record remains.
- Does not establish whether spacing and focus styling look good.
Browser capture
Makes the visible state available to a reviewer.
- Shows the selected filter, focus outline and actual cards together.
- Supports inspection of labels, wrapping and hierarchy.
- Needs the route, data state and viewport to be interpretable.
For automated screenshot comparisons, retain a deliberately reviewed reference and a consistent rendering environment. Playwright documents that operating system, browser and other host differences can change the pixels. A fresh screenshot is evidence to inspect; accepting it as the new reference is a separate editorial or engineering decision. Our before-and-after images are inspected captures, not a pixel-diff test. Read the visual-comparison guidance.
A compact review loop for an agent-assisted fix
Freeze the intended result
Write the initial records, action and exact visible result. Keep this acceptance condition in the review notes.
Demonstrate the original failure
Run the outcome assertion against the broken behavior. Confirm that the reported mismatch is the bug you intended to catch.
Inspect both edits
Review the implementation and the test. A removed expectation, broader locator or changed fixture can alter what a pass means.
Repeat and inspect
Run the same condition against the correction, test the return path, and inspect desktop and narrow-screen captures with their environment recorded.
A passing check becomes useful when you know what it would reject. For the next agent-generated UI fix, ask for the failing observation, the corrected result and the visual evidence together. That gives the reviewer a concrete basis for accepting the change and a test that can catch the same mistake again.
Back to the LOOKFILE blog