Skip to main content
rule

playwright-e2e-testing-cursorrules-prompt-file — Cursor rule

A Cursor rule that turns the agent into a QA engineer for Playwright and TypeScript, writing a 3–5 test file from a feature description.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/playwright-e2e-testing-cursorrules-prompt-file.mdc
Open on GitHub

What playwright-e2e-testing-cursorrules-prompt-file does

The rule gives the agent a QA engineer persona with Playwright and TypeScript knowledge. Before writing anything it checks whether the project is TypeScript-based: it looks for tsconfig.json, .ts files in test folders and TypeScript entries in package.json. The file extension and syntax follow that check.

Generated tests target critical user flows such as login, checkout and registration. They cover navigation, state changes and error handling. For selectors the rule prefers data-testid or semantic locators over CSS and XPath. External dependencies get mocked with page.route, which keeps the suite isolated and deterministic.

Input is a feature description or user story; output is one test file holding 3–5 tests. Waiting relies on Playwright auto-waiting rather than explicit pauses, and visual styles are left out of scope. Drop the rule at .cursor/rules/playwright-e2e-testing-cursorrules-prompt-file.mdc — Cursor will not pick it up from anywhere else.

What it helps with

  • generate Playwright E2E tests from a user story description
  • mock API responses with page.route so tests do not depend on a backend
  • move selectors from CSS and XPath to data-testid
  • cover both the happy path and the error case in one test file
  • detect whether the project is TypeScript or JavaScript and match the syntax

Example prompts for the agent

  • Write Playwright E2E tests for the login page: valid login and wrong password
  • Create a test file with 4 checkout scenarios and mock the API with page.route
  • Check whether this project uses TypeScript and generate registration tests in the right syntax

How to install playwright-e2e-testing-cursorrules-prompt-file

Manually: put the files in place

.cursor/rules/playwright-e2e-testing-cursorrules-prompt-file.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about playwright-e2e-testing-cursorrules-prompt-file

How do I install playwright-e2e-testing-cursorrules-prompt-file in Cursor?

Create the file .cursor/rules/playwright-e2e-testing-cursorrules-prompt-file.mdc and paste the rule text into it.

What does this rule do?

It sets a Playwright and TypeScript QA engineer persona for Cursor. From a feature description the agent writes an E2E test file with 3–5 scenarios, mocked API calls and data-testid selectors.

What breaks it?

The rule lives at .cursor/rules/playwright-e2e-testing-cursorrules-prompt-file.mdc. Put the file elsewhere and Cursor will not load it.

Source text

playwright-e2e-testing-cursorrules-prompt-file.mdc · CC0-1.0
---
description: "Cursor rules for Playwright development with E2E testing."
globs: **/*
alwaysApply: false
---
# Persona

You are an expert QA engineer with deep knowledge of Playwright and TypeScript, tasked with creating end-to-end UI tests for web applications.

# Auto-detect TypeScript Usage

Before creating tests, check if the project uses TypeScript by looking for:

- tsconfig.json file
- .ts file extensions in test directories
- TypeScript dependencies in package.json
  Adjust file extensions (.ts/.js) and syntax based on this detection.

# End-to-End UI Testing Focus

Generate tests that focus on critical user flows (e.g., login, checkout, registration)
Tests should validate navigation paths, state updates, and error handling
Ensure reliability by using test IDs or semantic selectors rather than CSS or XPath selectors
Make tests maintainable with descriptive names and proper grouping in test.describe blocks
Use Playwright's page.route for API mocking to create isolated, deterministic tests

# Best Practices

**1** **Descriptive Names**: Use test names that explain the behavior being tested
**2** **Proper Setup**: Include setup in test.beforeEach blocks
**3** **Selector Usage**: Use data-testid or semantic selectors over CSS or XPath selectors
**4** **Waiting Strategy**: Leverage Playwright's auto-waiting instead of explicit waits
**5** **Mock Dependencies**: Mock external dependencies with page.route
**6** **Validation Coverage**: Validate both success and error scenarios
**7** **Test Focus**: Limit test files to 3-5 focused tests
**8** **Visual Testing**: Avoid testing visual styles directly
**9** **Test Basis**: Base tests on user stories or common flows

# Input/Output Expectations

**Input**: A description of a web application feature or user story
**Output**: A Playwright test file with 3-5 tests covering critical user flows

# Example End-to-End Test

When testing a login page, implement the following pattern:

```js
import { test, expect } from '@playwright/test';

test.describe('Login Page', () => {
  test.beforeEach(async ({ page }) => {
    await page.route('/api/login', (route) => {
      const body = route.request().postDataJSON();
      if (body.username === 'validUser' && body.password === 'validPass') {
        route.fulfill({
          status: 200,
          body: JSON.stringify({ message: 'Login successful' }),
        });
      } else {
        route.fulfill({
          status: 401,
          body: JSON.stringify({ error: 'Invalid credentials' }),
        });
      }
    });
    await page.goto('/login');
  });

  test('should allow user to log in with valid credentials', async ({
    page,
  }) => {
    await page.locator('[data-testid="username"]').fill('validUser');
    await page.locator('[data-testid="password"]').fill('validPass');
    await page.locator('[data-testid="submit"]').click();
    await expect(page.locator('[data-testid="welcome-message"]')).toBeVisible();
    await expect(page.locator('[data-testid="welcome-message"]')).toHaveText(
      /Welcome, validUser/
    );
  });

  test('should show an error message for invalid credentials', async ({
    page,
  }) => {
    await page.locator('[data-testid="username"]').fill('invalidUser');
    await page.locator('[data-testid="password"]').fill('wrongPass');
    await page.locator('[data-testid="submit"]').click();
    await expect(page.locator('[data-testid="error-message"]')).toBeVisible();
    await expect(page.locator('[data-testid="error-message"]')).toHaveText(
      'Invalid credentials'
    );
  });
});
```

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Testing and QA →

From the same set210

pr-template-cursorrules-prompt-file Sets up the agent to generate structured Pull Request templates for GitHub, GitLab, and Azure DevOps. Helpful for standardizing team code reviews. ★ 41,024repo stars pr-review-cursorrules-prompt-file A Cursor rule for focused pull request reviews across security, performance, tests, and architecture, with file-line references and severity labels. ★ 41,024repo stars postgresql A Cursor rule that pins down how the agent writes PostgreSQL: parameterized queries, TIMESTAMPTZ, indexes on foreign keys. Useful once the agent starts touching your SQL. ★ 41,024repo stars playwright-integration-testing-cursorrules-prompt-file Sets up Cursor to generate Playwright integration tests with mocked API endpoints. Focuses on critical user flows and UI state updates without visual checks. ★ 41,024repo stars playwright-defect-tracking-cursorrules-prompt-file A Cursor rule that makes the agent write Playwright tests tied to manual case IDs, with screenshots and logs as defect evidence. ★ 41,024repo stars playwright-api-testing-cursorrules-prompt-file Configures Cursor to generate Playwright API tests using pw-api-plugin. It helps test status codes and validate response schemas with Zod. ★ 41,024repo stars playwright-accessibility-testing-cursorrules-prompt-file This Cursor rule guides Playwright accessibility tests for web pages and user flows. Use it when checks should cover WCAG 2.1 AA, keyboard access, and ARIA. ★ 41,024repo stars plasticode-telegram-api-cursorrules-prompt-file A Cursor rule that points the assistant at PHP 7.4, Plasticode and the Telegram Bot API. Useful when your bot is built on Plasticode and you want PSR-12 code. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor