Playwright Scripting Rules | Bondar Academy
Course: Claude Code for Playwright
Module: Playwright Workflows with Claude Code
Instructor: Artem Bondar
Lesson Summary
Playwright Scripting Rules define the behavior of the agent when creating tests. This document outlines the rules, practices, and patterns that the agent should follow. Here’s a detailed overview of the key concepts: Locator Priorities Use getByRole as the highest priority locator. If getByRole is unavailable, use getByLabel , getByText , or placeholders. Only use data-test-id when necessary and add it to the source code if it doesn't exist. Avoid using CSS selectors unless absolutely necessary. Best Practices for Locators Locator text must match the source code exactly. Ensure locators are unique to prevent interactions with multiple elements. Scope interactions to specific containers to avoid false positives. Use cross-page content linking for validations between pages. Assertions and Waiting Always use locator assertions and avoid soft assertions. Rely on Playwright's auto-waiting mechanism; avoid arbitrary timeouts. General Guidelines Tests should describe user behavior, not implementation details. Start from the homepage for navigation, mimicking user actions. Maintain a single logical flow per test. Use clear and descriptive naming conventions for variables and locators. This document is a living guide, evolving as the agent generates tests. Regular monitoring and updates are essential to ensure adherence to these rules and improve test quality over time.