Skip to content

Generate a .cursorrules File for a QA Codebase

AI Agent WorkflowsUpdated 2026-10-21intermediate
TL;DR

Returns a `.cursorrules` file tailored for QA work: locator preferences, anti-patterns to avoid, test naming conventions, assertion style, and rules for asking clarification before fabricating selectors or test data.

When to use it

  • Adding Cursor IDE to a QA codebase.
  • Reducing time spent fixing Cursor's auto-generated tests.
  • Standardizing AI assistance across QA engineers using Cursor.
  • Migrating from generic .cursorrules to QA-specific.

The prompt

XML-tagged: works best with Claude
cursorrules-qa.claude.mdprompt
<role>You are a Cursor power user. You know that .cursorrules dramatically improves output quality but only if rules are specific to the QA domain: generic rules ("write clean code") add no value.</role> <context>.cursorrules is loaded into every prompt Cursor sends to its underlying model. Good content:- Locator preferences (which to use, which to avoid)- Test naming conventions- Assertion patterns- Anti-patterns to NEVER produce- "Ask before guessing" rules (selectors, test data, env vars)- Framework-specific gotchas (Cypress chaining, Playwright auto-waiting, Vitest mocking semantics) The file is plain markdown / text. Keep < 150 lines; longer dilutes signal.</context> <task>Generate a `.cursorrules` with these sections:1. Project context (1-2 sentences)2. When generating tests3. When generating POMs4. Anti-patterns to NEVER produce5. Ask for clarification rules6. Style conventions</task> <input>Project framework: {framework}Language: {language}Locator strategy: {locator_strategy}Test data convention: {test_data}Known anti-patterns from your codebase: {anti_patterns}</input> <constraints>- Rules SPECIFIC, not generic ("Use data-testid first, not class selectors").- Anti-patterns called out by NAME (waitForTimeout, magic numbers, etc.).- "Ask before guessing" must be explicit (clarify which scenarios).- Style conventions named, not implied.- 80-150 lines total.</constraints> <output_format>A complete `.cursorrules` file inside a FOUR-backtick fence (````markdown), so code examples inside it don't close the outer block. Write the same content to `.cursor/rules/qa.mdc` if the project uses Cursor's newer Project Rules.</output_format> <approach>Before writing, identify the 3-5 most common pain points in this team's Cursor output and address them in the file.</approach>

Example

Input
Project framework: Playwright + TypeScript
Language: TypeScript strict
Locator strategy: getByRole > getByLabel > getByTestId > CSS (CSS only as last resort, with comment explaining why)
Test data convention: Factories in src/fixtures/. No inline emails / IDs. Test domain @test.example.com.
Known anti-patterns from your codebase: page.waitForTimeout (Cursor frequently generates these), magic numbers in assertions, inventing data-testid values that don't exist
Output
````markdown
# .cursorrules: QA Project

## Project context

This is the Playwright + TypeScript E2E test suite for our product. Tests use Page Object Model. Locators follow accessibility-first priority. Test data is factory-generated, never inline.

## When generating Playwright tests

- Use `expect(locator).toBeVisible()` (and similar) for waits: these auto-wait. NEVER use `page.waitForTimeout` or any hard sleep.
- Use POM methods imported from `src/pages/`. Do NOT inline locators in spec files.
- Test names describe behavior: `"signs in with valid credentials and redirects to dashboard"`, not `"test login"`.
- Use `describe.serial` only if tests genuinely must run in order (rare). Default to independent tests.
- One concept per test. One assertion can have multiple expect() lines, but the test verifies ONE behavior.
- All Playwright API calls are async; remember `await`.

## When generating POMs

- Locator priority STRICTLY: `getByRole` > `getByLabel` > `getByTestId` > CSS.
- If a CSS selector is the only option, ADD A COMMENT explaining why role/label/testid don't apply.
- Initialize all locators in the constructor. Use `readonly` typing.
- Action methods named in verb form: `signIn`, `addToCart`, `applyDiscount`. NOT `clickX` for every click.
- Assertion methods prefixed with `assert`: `assertOnDashboard`, `assertErrorVisible`.
- One POM per page or component. Don't mix multi-page methods in one class.

## Anti-patterns to NEVER produce

These are wrong; do not generate code containing them:

- `page.waitForTimeout(ms)`: use `expect(locator).toBeX()` auto-waiting instead.
- `.locator('.css-class-name')` without justification.
- Inline test data: `page.fill('email', 'test@example.com')`. Use factories from `src/fixtures/`.
- Magic numbers in assertions: `expect(items).toHaveCount(7)` should reference a constant explaining why 7.
- `it.only` / `test.only` / `.skip`: these MUST not appear in committed code.
- `console.log` for debugging: use Playwright's `test.info().annotations`.
- `@ts-ignore` or `@ts-expect-error` without a comment explaining why the type system is being bypassed.
- Inventing `data-testid` values without verifying they exist in the product app. If unsure, ask.

## Ask before guessing

If any of the following are unclear, ASK rather than guess:

- The exact `data-testid`, role name, or label of an element. (Inventing these creates broken tests.)
- The expected behavior when a spec is ambiguous. (Inventing assertions hides the ambiguity.)
- Whether a new fixture should be added to `src/fixtures/` or inline in the spec.
- Whether a flow belongs in an existing POM or warrants a new one.
- Whether a test should be unit, integration, or E2E.
- Environment variables (BASE_URL, TEST_BEARER, etc.): refer to existing `.env.example`.

## Style conventions

- TypeScript strict: no `any` (use `unknown` if truly unknown).
- Async functions: arrow when local; named function declaration when exported.
- File names: kebab-case (`discount-flow.spec.ts`, not `DiscountFlow.spec.ts`).
- Imports: absolute path via `@/` alias for src imports, relative for sibling files.
- No default exports for utilities: named exports only. Default exports OK for POM classes.
- Test files end in `.spec.ts`; helpers and POMs end in `.ts`.

## When refactoring

- Don't rewrite passing tests unless explicitly asked. Small refactors only.
- Preserve existing assertion intent: if a test currently asserts X, the rewrite must still assert X (or a stricter form).
- When in doubt, leave the existing test and add a comment.

## Quick reference

```typescript
// GOOD
const submit = page.getByRole('button', { name: 'Sign in' });
await expect(submit).toBeVisible();
await submit.click();

// BAD
const submit = page.locator('.btn-primary');
await page.waitForTimeout(2000);
await submit.click();
```
````

Common pitfalls

  • Rules become generic ('write good code'); force specifics tied to your stack.
  • Anti-patterns called out without naming the specific construct (e.g., 'avoid waits' vs 'no page.waitForTimeout').
  • Ask-before-guessing rules missing; Cursor fabricates selectors / data without asking.
  • .cursorrules file balloons past 200 lines; signal dilutes. Keep tight.

Tips

  • Test the .cursorrules by giving Cursor a small task and watching the output; refine rules iteratively.
  • Pair with `claude-md-for-qa` for the Claude Code equivalent in the same repo.
  • Refresh when major framework versions land (Playwright 1.55 → 1.62, etc.).
  • Document team-specific style conventions in the file; they get applied automatically across all Cursor invocations.

FAQ

Cursor vs Continue vs Cody?

Cursor (most popular in 2026): native AI IDE with .cursorrules + composer + commands. Continue: open-source VS Code extension; similar concept. Cody (Sourcegraph): code-search powered AI; great for large codebases. All accept similar instruction files; the format differs.

Project vs global .cursorrules?

Project-level rules are shared with the team via git: Cursor's current format is Project Rules in `.cursor/rules/*.mdc` (scoped by glob, e.g. only `tests/**`), and the legacy `.cursorrules` file in the repo root is still read. User Rules in Cursor settings are personal across all projects. Use project-level for team conventions, user-level for personal preferences.

How often should I refresh .cursorrules?

After major framework upgrades, after Cursor introduces new features, after spotting repeated mistakes in Cursor output. Roughly quarterly review minimum.

Does .cursorrules conflict with CLAUDE.md or AGENTS.md?

No: each assistant loads its own file (Cursor: `.cursor/rules` / `.cursorrules`; Claude Code: CLAUDE.md; Codex and others: AGENTS.md, which Cursor also reads). Keep one file as the source of truth and have the others reference it, so the rules don't drift apart.