BMAD-METHOD/.claude/rules/playwright-e2e-testing-curs.../README.md

20 lines
3.0 KiB
Markdown

# Playwright E2E Testing .cursorrules prompt file
Author: Peter M Souza Jr
## What you can build
End-to-End Test Suite: Create a comprehensive end-to-end test suite for web applications that validates critical user flows such as login, registration, checkout, and other key interactions. The tests focus on validating navigation paths, state updates, and error handling scenarios to ensure application reliability.Modern Testing Framework: Develop a robust testing framework using Playwright that leverages built-in auto-waiting, powerful selectors, and network interception capabilities. This framework improves test reliability and maintainability while reducing flaky tests.Cross-Browser Testing Solution: Implement tests that run across multiple browsers (Chromium, Firefox, WebKit) with a single codebase, ensuring consistent behavior across different browser engines.Mobile Emulation Tests: Create tests that validate your application's behavior on mobile devices by leveraging Playwright's device emulation capabilities, without requiring separate mobile-specific code.Visual Validation Workflow: Build a testing workflow that can capture and compare screenshots for visual regression testing, helping catch unexpected UI changes across different browsers and viewports.
## Benefits
Auto-Waiting Mechanism: Leverages Playwright's built-in auto-waiting, eliminating the need for explicit waits and reducing flaky tests.TypeScript Auto-Detection: Automatically identifies TypeScript projects and adjusts test code syntax accordingly, enabling type safety without manual configuration.Cross-Browser Compatibility: Provides a single codebase that works across Chromium, Firefox, and WebKit browsers with minimal configuration.Modern API Approach: Uses async/await patterns and powerful selectors for more readable and maintainable test code.Powerful Mocking Capabilities: Includes robust network interception for API mocking and request manipulation during tests.
## Synopsis
This prompt helps web developers create reliable, maintainable end-to-end test suites for their applications using Playwright, focusing on critical user flows and behavior validation across multiple browsers.
## Overview of .cursorrules prompt
The .cursorrules file provides guidance for QA engineers and developers creating end-to-end UI tests with Playwright. It takes a TypeScript-aware approach, automatically detecting and adapting to TypeScript projects when present. The prompt focuses exclusively on end-to-end testing, emphasizing critical user flows and proper test structure. It promotes best practices like using test IDs or semantic selectors, leveraging Playwright's auto-waiting, mocking external dependencies with page.route, and creating focused test files with 3-5 tests each. The prompt includes a comprehensive example of a login test that demonstrates proper setup, API mocking, interaction patterns, and assertions for both success and error scenarios. Tests created with this prompt validate navigation paths, state updates, and error handling to ensure reliable applications.