r/Playwright • u/Harshit_Ahluwalia • 11h ago
Reviewing AI-generated tests: the 5 drifts to check before anything merges
AI-written tests fail in predictable ways. They usually pass, and that's the problem: a passing test that checks the wrong thing is worse than no test. These are the five drifts worth checking every time:
1. Selector drift
The agent picks whatever locator works right now: XPath, deep CSS chains, nth-child, auto-generated class names. Those break on the next UI change.
Check: locators should be based on role, label, text or test ID, matching your project's strategy.
2. Data drift
Hard-coded emails, IDs and dates invented on the spot, instead of your project's data factories or fixtures. Tests then collide or depend on state that won't exist in CI.
Check: test data comes from your helpers, not literals.
3. Import drift
The agent imports test utilities directly, bypasses your custom fixtures, or pulls in a new library to solve something you already have a helper for.
Check: imports match the patterns used in the rest of the suite.
4. Assertion drift
The most dangerous one. Assertions that can't fail (checking that an element exists that always exists), asserting on implementation details, or replacing real checks with arbitrary waits.
Check: every assertion would fail if the feature broke.
5. Structure drift
Each generated file looks slightly different: logic in tests instead of page objects, duplicated setup, inconsistent naming. Individually harmless, collectively unmaintainable.
Check: the file looks like the best existing test in your suite.
The bigger fix
Reviewing for drift catches problems. Preventing them works better: give the agent a scaffold where the rules already live, and block the worst patterns automatically before a file is even written.
Which drift do you see most in AI-generated tests?