Sitemap
Anton Gulin

Anton Gulin

AI QA Architect | Playwright + TypeScript | Former Apple SDET | Building AI-Powered Test Automation Systems

Member-only story

Playwright Best Practices: 10 Rules AI Agents Get Wrong (2026)

6 min readJun 21, 2026

--

Press enter or click to view image in full size

Playwright Best Practices: 10 Rules AI Agents Get Wrong (2026)

Playwright best practices are the rules that keep browser tests stable and easy to read. Use role-based locators (find by what users see), web-first assertions that auto-wait, and isolated tests. Seed data through the API (direct requests), not the UI. Avoid hard waits, conditional logic, and tests tied to your HTML. Turn on traces and run in parallel.

An AI agent can write 50 Playwright tests in a minute. That feels fast.

Then those tests fail at random, and nobody knows why. The agent copied old patterns from its training data. It does not know the run failed last night.

This guide lists the 10 best practices that keep tests stable. For each one, I show a small correct example. I also show what AI code agents get wrong. AI tools like Copilot, Cursor, and even Playwright codegen (the test recorder) lean on stale habits. Someone has to fix that.

1. Find elements the way a user sees them

A locator (a pointer to an element) should match what a person sees on screen. Use getByRole, getByLabel, or getByText. These read like the page. They also survive a redesign of your HTML.

--

--

Anton Gulin
Anton Gulin

Written by Anton Gulin

AI QA Architect | Playwright + TypeScript | Former Apple SDET | Building AI-Powered Test Automation Systems