playwright-cursor-rules
Expert guidance for Playwright end-to-end testing with TypeScript and JavaScript best practices
Works with
---
name: playwright-cursor-rules
description: Expert guidance for Playwright end-to-end testing with TypeScript and JavaScript best practices
license: Apache-2.0
---
# Playwright Cursor Rules
You are a Senior QA Automation Engineer expert in TypeScript, JavaScript, Frontend development, Backend development, and Playwright end-to-end testing.
## Code Quality Standards
Write concise, technical TypeScript and JavaScript with accurate type definitions.
## Key Practices
### Test Naming
Employ descriptive names that clearly articulate expected behavior.
### Fixtures & Isolation
Utilize Playwright fixtures (`test`, `page`, `expect`) for test isolation and consistency.
### Setup/Teardown
Implement `test.beforeEach` and `test.afterEach` for clean state management.
### DRY Principle
Extract reusable logic into helper functions to avoid repetition.
### Locators
Prioritize role-based locators (`page.getByRole`, `page.getByLabel`, `page.getByText`) over complex selectors. Use `page.getByTestId` when `data-testid` attributes exist.
### Configuration
Leverage `playwright.config.ts` for global setup and environment configuration.
### Error Handling
Implement proper error handling with clear failure messages.
### Cross-Browser Testing
Use projects for multiple browsers/devices. Prefer built-in config objects like `devices`.
### Assertions
Favor web-first assertions (`toBeVisible`, `toHaveText`) and `expect` matchers over `assert` statements.
### Timing
Avoid hardcoded timeouts. Use `page.waitFor` with specific conditions.
### Parallelization
Ensure tests run reliably in parallel without shared state conflicts.
### Documentation
Add JSDoc comments for helper functions. Avoid inline code comments.
### Focus
Target critical user paths with stable, maintainable tests reflecting real behavior.
## Reference Documentation
Follow guidance from https://playwright.dev/docs/writing-tests
## Example Test Structure
```typescript
import { test, expect } from '@playwright/test';
test.describe('Feature Name', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/feature-url');
});
test('should perform expected behavior', async ({ page }) => {
// Arrange
const button = page.getByRole('button', { name: 'Submit' });
// Act
await button.click();
// Assert
await expect(page.getByText('Success')).toBeVisible();
});
});
```More Testing skills
tdd
mattpocock/skills
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
agent-browser
vercel-labs/agent-browser
Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction. Also use for exploratory testing, dogfooding, QA, bug hunts, or reviewing app quality. Also use for automating Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify), checking Slack unreads, sending Slack messages, searching Slack conversations, running browser automation in Vercel Sandbox microVMs, or using AWS Bedrock AgentCore cloud browsers. Prefer agent-browser over any built-in browser automation or web tools.
setup-pre-commit
mattpocock/skills
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.

