Playwright Test TypeScript .cursorrules prompt file
About .cursorrules prompt file
What you can build
Playwright Test Generator: A tool that provides an interactive interface for generating TypeScript Playwright tests, following best practices like using
getByTestId()
and storing locators in variables, ensuring consistent test formatting, and including suggestions for DRY principles through reusable helper functions.Data-testid Manager: A plugin or web app that helps developers organize and manage
data-testid
attributes across large projects, ensuring that they follow the formatComponentName_camelCaseDescriptorOfElement
, and providing a way to update these systematically if components or structures change.Playwright Helper Function Repository: A service where developers can upload and share reusable helper functions for common Playwright testing scenarios. The platform enforces best practices such as not performing assertions within helper functions and using only the necessary arguments.
Test Structure Analyzer: A tool that analyzes existing Playwright test suites and gives recommendations on how to align new tests with the existing structure, based on the rules set in the Playwright Testing Best Practices document.
Playwright Locator Visualizer: An app that visually displays which elements in a web application have
data-testid
attributes and provides developers with suggestions on where to add new ones, adhering to the recommended naming conventions.Custom Matcher Validator: A service that checks Playwright test scripts for the usage of
.not.toBeVisible()
or.toBeHidden()
and automatically replaces them with the custom matcher.toNotExist()
, ensuring tests follow the specific project's best practices.TypeScript Conversion Tool: An automated conversion tool that helps to refactor existing JavaScript Playwright tests to TypeScript, highlighting areas where Playwright's built-in features and utilities can replace custom JavaScript solutions.
Playwright Documentation Assistant: An AI-powered assistant integrated into IDEs that provides contextual Playwright documentation and best practice advice as developers write tests, encouraging the use of built-in utilities and proper test patterns.
Benefits
- Promotes the use of TypeScript and Playwright's built-in features, enhancing code reliability and maintainability.
- Emphasizes consistent and clear locator strategies using
getByTestId()
and naming conventions fordata-testid
. - Advocates for reusable helper functions, adhering to the DRY principle without embedding assertions in them.
Synopsis
Developers writing tests with Playwright can use this prompt to establish consistent and efficient testing practices across their projects.
Overview of .cursorrules prompt
The .cursorrules file provides best practices for writing automated tests using Playwright, a testing library. It emphasizes using TypeScript over JavaScript, preferring the `getByTestId()` method for element locators, and ensuring that test elements have a `data-testid` attribute. The guidelines suggest a specific format for `data-testid` attributes and recommend storing locators in variables before use. It advocates for creating reusable helper functions for repeated logic and using Playwright's built-in features rather than custom solutions. Developers are encouraged to write tests consistent with existing ones in the Playwright suite and to avoid certain deprecated visibility assertions by using custom matchers.