AI can write a Playwright test in seconds. That is the easy part. The hard part is knowing whether the test is worth keeping, because a test that passes proves nothing unless it can also fail.

Over the last months I have leaned on AI to write first drafts of tests, and the review step is where the real work moved. This is the order I follow when I review a test an AI wrote.

1. Read the assertion first

Generated tests love to check that a page loaded. They click through a flow and end by confirming that some element is visible. That is a smoke check, not a test of the business rule. Ask what the rule is, for example that a refund cannot exceed the original payment, and check that the assertion actually tests it. If the assertion would still pass when the rule is broken, it is not doing its job.

2. Fail it on purpose

Before trusting a green result, break the feature or change the expected value and run the test again. It should go red. A green you have never seen go red proves nothing. This one step catches most weak tests, because a test that cannot fail will happily stay green while the product breaks.

3. Check the locator

Prefer locators that describe what the user sees, such as a role and a name, or a stable test id. Be wary of long CSS paths and text that changes with every release. A brittle locator turns a good test into a flaky one, and a flaky suite teaches the team to ignore red.

4. Check the test data

Generated tests often reuse data that other tests also touch, or leave records behind. Each test should create what it needs and clean up after itself, so it passes in any order and in any environment. Shared data is a common source of failures that disappear when you run the test again.

What I hand to AI, and what I keep

Page objects, boilerplate, and first drafts of test data are safe to hand over, as long as a review is built in. The assertion and the decision about what matters stay with a person, because only a person knows which rule the business cannot afford to break.

Speed from AI is real, but trust still has to be earned by the review. A short checklist, applied every time, is what turns fast drafts into a test suite you can rely on.

What do you check first when you review an AI-generated test: the assertion, the locator, or the test data?

Originally published on Medium.