Over time, certain bad habits and shortcuts can creep into a Playwright suite. Recognising anti-patterns early helps you keep tests fast, reliable and maintainable.
Common Playwright Anti-patterns
Examples include overusing hard waits, relying on brittle selectors, mixing concerns across layers and writing overly long tests.
// Examples of anti-patterns
// 1. Hard-coded waits
await page.waitForTimeout(5000); // β avoid when possible
// 2. Brittle CSS selectors
await page.locator('div:nth-child(3) > span.button'); // β fragile
// 3. Giant tests covering many flows
// β difficult to debug and maintain
Note: Replacing these patterns with locators, auto-waiting assertions, fixtures and page models usually improves both readability and stability.
Tip: Review the suite periodically for smells such as repeated waitForTimeout calls or selectors that depend on visual structure.
Warning: Ignoring early warning signs leads to a gradual decline in test quality and confidence.
Agreeing on a short list of βbanned patternsβ can help teams avoid reintroducing them.
Common Mistakes
Mistake 1 β Accepting flaky tests as normal
This lowers standards.
β Wrong: Marking tests as flaky without investigation.
β Correct: Use flakiness as a signal to improve design or infrastructure.
Mistake 2 β Ignoring maintainability when adding tests
This creates long-term pain.
β Wrong: Optimising only for speed of writing, not readability.
β Correct: Invest in patterns that keep the suite healthy over time.