Playwright Cursor Rules

Mindrally/skills/playwright-cursor-rules

作者 Mindrally7682ca77710e0971eab4e0ae5dddfa281aea0ba5无许可证269 个星标收录于 2026年10月8日更新于 2026年10月9日仓库5周前更新

Expert guidance for Playwright end-to-end testing with TypeScript and JavaScript best practices

AI 生成的概览

为使用 TypeScript 和 JavaScript 编写 Playwright 端到端测试提供符合 QA 最佳实践的指导。

功能
该技能提供一套用于编写 Playwright 端到端测试的编码规范与约定,适用于 TypeScript 和 JavaScript。内容涵盖测试命名、fixture 与隔离、setup/teardown、DRY 辅助函数抽取、基于角色的定位器、配置、错误处理、跨浏览器项目、web-first 断言、时序、并行化以及文档。它还包含一个使用 test.describe、beforeEach 和 expect 的示例测试结构。
适用场景
适用于编写或审查 Playwright 端到端测试,并希望采用一致且易维护的模式时。适合需要在整套测试中统一测试结构、定位器策略和断言风格的团队。
运行要求
不附带脚本或软件包,仅为指导说明。遵循该指导需要项目已具备 Playwright 及其测试运行器,以及 TypeScript 或 JavaScript 工具链。

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();  });});

来源与署名

来源:Mindrally/skills位于playwright-cursor-rules提交7682ca7

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架