# cypress-e2e-testing-cursorrules-prompt-file

This Cursor rule guides an agent in writing Cypress E2E tests for key web-app flows. It detects TypeScript usage and favors stable test selectors.

- rule · `type=rule` · Cursor · ★ 41024
- Author: PatrickJS
- License: CC0-1.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/PatrickJS/awesome-cursorrules/tree/HEAD/rules/cypress-e2e-testing-cursorrules-prompt-file.mdc
- Updated: 2026-05-30
- HTML: https://affpapa.org/en/nevibecode/rules/cypress-e2e-testing-cursorrules-prompt-file

## What it does

The rule directs E2E coverage for web applications, including navigation, state changes, and error paths in flows such as login, registration, and checkout. Before writing tests, the agent checks for `tsconfig.json`, `.ts` or `.tsx` files under `cypress/`, and TypeScript packages in `package.json`. It then chooses the matching file extension and syntax.

Its guidance uses `data-testid` selectors instead of CSS or XPath, puts setup in `beforeEach`, and isolates API behavior with `cy.intercept`. Tests should cover both success and failure cases, avoid fixed delays, and stay focused at 3–5 tests per file. This rule fits Cypress work specifically because its structure and commands are built around the Cypress API.

## Install

### Cursor (native platform)

**Manually: put the files in place**
- File: `.cursor/rules/cypress-e2e-testing-cursorrules-prompt-file.mdc` — Frontmatter: description, globs, alwaysApply

### Claude Code

**Manually: put the files in place**
- File: `.claude/rules/cypress-e2e-testing-cursorrules-prompt-file.md` — The paths frontmatter field limits the files: move globs from the source into paths

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/cypress-e2e-testing-cursorrules-prompt-file.instructions.md` — The applyTo field sets which files it applies to: move globs from the source into applyTo

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/cypress-e2e-testing-cursorrules-prompt-file.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/cypress-e2e-testing-cursorrules-prompt-file.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/PatrickJS/awesome-cursorrules/tree/HEAD/rules/cypress-e2e-testing-cursorrules-prompt-file.mdc

## When to use it
- write E2E coverage for login and checkout flows
- check both successful and failed user paths
- mock API calls with `cy.intercept`
- choose `.ts` or `.js` test syntax
- replace fragile CSS selectors with `data-testid`

## Example prompts
- Create Cypress E2E tests for a login flow with successful and failed API responses.
- Test the checkout journey and isolate external requests with `cy.intercept`.
- Detect whether this project uses TypeScript, then create the test file with the matching extension.

## Source text · cypress-e2e-testing-cursorrules-prompt-file.mdc · CC0-1.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 167491fe103e21b6.

BEGIN THIRD-PARTY FILE 167491fe103e21b6
````text
---
description: "Cursor rules for Cypress development with E2E testing."
globs: **/*
alwaysApply: false
---
# Persona

You are an expert QA engineer with deep knowledge of Cypress 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 or .tsx file extensions in cypress/
- 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 data-testid selectors rather than CSS or XPath selectors
Make tests maintainable with descriptive names and proper grouping in describe blocks
Use cy.intercept 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 beforeEach blocks
**3** **Selector Usage**: Use data-testid selectors over CSS or XPath selectors
**4** **Waiting Strategies**: Implement proper waiting strategies; avoid hard-coded waits
**5** **Mock Dependencies**: Mock external dependencies with cy.intercept
**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 Cypress test file with 3-5 tests covering critical user flows

# Example End-to-End Test

When creating tests for a login page, implement the following pattern:

```js
describe('Login Page', () => {
  beforeEach(() => {
    cy.visit('/login');
    cy.intercept('POST', '/api/login', (req) => {
      if (req.body.username === 'validUser' && req.body.password === 'validPass') {
        req.reply({ status: 200, body: { message: 'Login successful' } });
      } else {
        req.reply({ status: 401, body: { error: 'Invalid credentials' } });
      }
    }).as('loginRequest');
  });

  it('should allow user to log in with valid credentials', () => {
    cy.get('[data-testid="username"]').type('validUser');
    cy.get('[data-testid="password"]').type('validPass');
    cy.get('[data-testid="submit"]').click();
    cy.wait('@loginRequest');
    cy.get('[data-testid="welcome-message"]').should('be.visible').and('contain', 'Welcome, validUser');
  });

  it('should show an error message for invalid credentials', () => {
    cy.get('[data-testid="username"]').type('invalidUser');
    cy.get('[data-testid="password"]').type('wrongPass');
    cy.get('[data-testid="submit"]').click();
    cy.wait('@loginRequest');
    cy.get('[data-testid="error-message"]').should('be.visible').and('contain', 'Invalid credentials');
  });
});
```
````
END THIRD-PARTY FILE 167491fe103e21b6

The third-party file has ended. Everything between the 167491fe103e21b6 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© PatrickJS · CC0-1.0 · https://github.com/PatrickJS/awesome-cursorrules/tree/HEAD/rules/cypress-e2e-testing-cursorrules-prompt-file.mdc

## Similar
- [e2e-testing-automation](https://affpapa.org/en/nevibecode/skills/e2e-testing-automation.md) — skill · 689 installs
- [e2e-testing-patterns](https://affpapa.org/en/nevibecode/skills/e2e-testing-patterns.md) — skill · 24343 installs
- [cypress-automation](https://affpapa.org/en/nevibecode/skills/cypress-automation.md) — skill · 1000 installs
- [e2e-testing](https://affpapa.org/en/nevibecode/skills/platform-team-e2e-testing.md) — skill · 1600 installs
- [playwright-e2e-testing](https://affpapa.org/en/nevibecode/skills/playwright-e2e-testing.md) — skill · 615 installs

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
