THE REPLACEQA BLOG
How to verify AI-generated Playwright tests catch real bugs
Review AI-generated Playwright tests against real requirements, introduce controlled faults and check that passing tests reject broken behavior.
To verify an AI-generated Playwright test, compare its assertions with an independently stated requirement, run it against working behavior, and then introduce a few controlled faults. A useful test should accept the working version and reject the relevant broken versions. Successful execution alone tells you much less.
This is a review method for an individual test. It does not prove complete application coverage or establish that one generator is better than another. The same method works for a test written by a person.
Keep the requirement outside the test
Consider a fictional seat calculator. Each seat costs $12. A visitor enters three seats, presses Calculate and sees $36. If they then enter five seats and calculate again, the result must change to $60.
Those values come from the fixture's stated pricing rule. They are not read from the current result element and reused as their own expected values. That separation is what lets the test detect an incorrect calculation.
A requirement should also identify the transition. A test that checks the first calculation can still miss a calculator that stops updating after its first submission. Write both actions into the acceptance condition when both matter.
For changing lists and titles, the independent expectation may be the identity of the selected record rather than fixed text. Our dynamic-content testing guide covers that case.
Inspect the assertions before running anything
Read the generated source alongside the requirement. Locate the assertion that corresponds to each promised outcome. If you cannot find one, a green result cannot establish that outcome.
Use this small review table:
| Review question | Calculator example |
|---|---|
| Is the starting state explicit? | Fresh page at /calculator |
| Are actions directed at the intended controls? | Seats input and Calculate button |
| Is the expected result independent? | $36 and $60 from the specified $12 rate |
| Does the test observe the important transition? | A second submission updates the first result |
| Could the test pass without completing the task? | A visibility-only assertion could accept the wrong total |
| What remains outside the check? | Tax, discounts, invalid inputs and other pricing rules |
Playwright recommends testing user-visible behavior and keeping tests independent. Those principles help the test express a customer task rather than an incidental implementation detail. See its best-practices guide.
Compare a candidate with a deliberately weak check
The downloadable example package contains an AI-authored candidate prepared for this article. Its exact task contract and provenance are in generation.json. It was generated with the two-submission requirement above, so it is not a blind evaluation of a tool asked to discover its own requirements.
The candidate's core is:
await page.goto('/calculator');
await page.getByRole('spinbutton', { name: 'Seats' }).fill('3');
await page.getByRole('button', { name: 'Calculate', exact: true }).click();
await expect(page.getByRole('status')).toHaveText('$36');
await page.getByRole('spinbutton', { name: 'Seats' }).fill('5');
await page.getByRole('button', { name: 'Calculate', exact: true }).click();
await expect(page.getByRole('status')).toHaveText('$60');
The package also contains a deliberately weakened teaching comparison. It performs only the first calculation and checks that the result is not empty:
await expect(page.getByRole('status')).not.toBeEmpty();
That comparison was constructed to illustrate weak coverage. It is not a bad output attributed to another model or a representative sample of generated tests. It can detect a missing result, but it never establishes that the result is numerically correct.
Introduce faults one at a time
After extracting the archive, install its locked dependencies and browser:
npm ci
npx playwright install chromium
npx playwright test tests/calculator.spec.js
Then exercise separate defects. These environment-variable examples use Linux/macOS shell syntax:
DEMO_FAULT=wrong-total npx playwright test tests/calculator.spec.js
DEMO_FAULT=no-submit npx playwright test tests/calculator.spec.js
DEMO_FAULT=stale-total npx playwright test tests/calculator.spec.js
The server changes the application behavior while the tests stay unchanged. wrong-total charges $10 per seat. no-submit leaves the result empty. stale-total calculates once and ignores later submissions. Each invocation starts a fresh fixture process.
Here are the observed results from local Chromium runs using Playwright Test 1.63.0:
| Fixture behavior | Candidate with both totals | Weakened comparison |
|---|---|---|
| Correct calculations | Pass | Pass |
| Wrong rate: $10 per seat | Fail at $36 expectation | Pass |
| Submit has no effect | Fail at $36 expectation | Fail because result stays empty |
| Second submission keeps old total | Fail at $60 expectation | Pass |
The candidate caught all three selected faults, so this example did not require weakening or rewriting its expected values to obtain a pass. The comparison demonstrates why a test can have some fault-detection value while still missing the main requirement. The archive includes the recorded matrix in evidence.json.
Review the failure reason, not just the exit code
A broken fixture should fail at an assertion relevant to the defect. A browser that did not launch, a missing package or an unrelated locator timeout does not demonstrate that the test detected a wrong price.
Keep the original source and evidence. Record which application fault was enabled and inspect the failing assertion. If the generated test misses a fault, improve its expectation against the original requirement and rerun the same matrix. Do not change the product's expected behavior merely to make the test green.
For unexplained failures, use the trace investigation workflow. It helps separate what the browser observed from your assumptions about why it happened.
Record what the review established
A useful acceptance note is specific: “Candidate revision A passed the healthy calculator and rejected the wrong-rate, ignored-submit and stale-second-result variants in local Chromium.” It does not say “the calculator is fully tested.”
This demonstration leaves input validation, rounding, discounts and real billing integration outside its scope. Add cases when they correspond to actual requirements and risks. Preserve any faults the test did not detect as visible gaps rather than hiding them behind a total pass count.
ReplaceQA retains generated source and validation evidence for public journeys. Request closed-beta access to explore that workflow, and use independent requirements and fault checks when deciding whether generated tests deserve your trust.