Playwright TypeScript Guide .cursorrules prompt file
About .cursorrules prompt file
What you can build
Playwright Helper Function Library: A library that helps users create reusable helper functions in Playwright, providing a set of pre-built functions to manage common tasks, such as form submissions and error handling, while following best practices.
Intelligent Locator Suggestion Tool: An application that analyzes a webpage's DOM and suggests the most efficient Playwright locator methods in the recommended hierarchy (e.g.,
getByTestId()
,getByRole()
, etc.) for targeting elements.DRY Principle Test Suite Generator: A tool that takes a set of Playwright test case requirements and generates a test suite optimized for reusability and minimal redundancy, creating helper functions as needed.
Playwright Project Template Generator: A service that generates boilerplate Playwright projects adhering to best practices, including TypeScript setup, recommended locator strategies, and folder structures.
Auto Documentation for Playwright Tests: An app that automatically generates comprehensive documentation for Playwright test suites, highlighting use of helper functions, locator strategies, and adherence to best practices.
Playwright Locator Optimization Plugin: A plugin for popular code editors that analyzes existing Playwright tests and suggests improvements to locator usage, ensuring the use of the most appropriate and efficient methods.
Reusable Logic Finder: A tool that scans Playwright test suites to identify repetitive logic and recommend the creation of reusable utility functions, promoting DRY practices.
Playwright Learning Platform: A website offering interactive tutorials and exercises focused on Playwright best practices, including efficient locator strategies and the use of built-in methods.
Playwright Test Refactoring Service: A service that refactors existing Playwright test code, aligning it with best practices by improving locator methods, employing helper functions, and reducing redundant logic.
Practice Environment for Playwright Beginners: An application that provides a sandbox environment for developers to practice writing Playwright tests, with automated feedback on adherence to best practices.
Benefits
- Emphasizes using TypeScript and Playwright's built-in locators with a clear fallback hierarchy for targeting elements.
- Reinforces DRY principles by encouraging reusable helper functions without assertions for shared logic.
- Promotes leveraging Playwright's built-in features over custom JavaScript solutions for reliability and consistency.
Synopsis
Developers using Playwright for end-to-end testing would benefit from these practices to build consistent, maintainable, and efficient automated test suites.
Overview of .cursorrules prompt
The .cursorrules file outlines best practices for using Playwright, a testing framework. It advises developers to use TypeScript over JavaScript and prioritizes certain locator methods for targeting elements, with `getByTestId()` being the preferred option. The file stresses the importance of storing locators in variables before utilizing them in tests and encourages the creation of reusable helper functions to uphold the DRY principle, without including assertions in these functions. Additionally, it advocates for leveraging Playwright's built-in utilities over custom solutions. The file also suggests aligning new tests with existing tests in the Playwright suite to maintain consistency.