Skip to main content
rule

cypress-e2e-testing-cursorrules-prompt-file — Cursor rule: install

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.

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

What cypress-e2e-testing-cursorrules-prompt-file 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.

What it helps with

  • 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 for the agent

  • 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.

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

Manually: put the files in place

.cursor/rules/cypress-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 cypress-e2e-testing-cursorrules-prompt-file

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

Create .cursor/rules/cypress-e2e-testing-cursorrules-prompt-file.mdc and place the rule in that file.

What does cypress-e2e-testing-cursorrules-prompt-file do?

It guides the agent to create Cypress tests for key UI flows, covering navigation, state, errors, and isolated API behavior.

How does the rule detect TypeScript?

The agent checks tsconfig.json, file extensions under cypress/, and TypeScript dependencies in package.json, then selects .ts or .js syntax.

Source text

cypress-e2e-testing-cursorrules-prompt-file.mdc · CC0-1.0
---
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');
  });
});
```

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

Similar IDE rules

All IDE rules for Testing and QA →

From the same set210

docker Cursor rule enforcing production Docker practices. Generates minimal, hardened containers with non-root users, layer caching, and pinned base images. ★ 41,024repo stars deno-integration-techniques-cursorrules-prompt-fil This rule gives Cursor context for Deno automation scripts and workflows. It fits repositories built around the @findhow packages. ★ 41,024repo stars database A Cursor rule with database practices for Prisma and Supabase: schemas, migrations, queries, RLS policies. Scoped to database files by glob. ★ 41,024repo stars cypress-integration-testing-cursorrules-prompt-file Guides Cursor to generate Cypress integration tests for UI and API flows. Enforces API mocking with cy.intercept and reliable data-testid selectors. ★ 41,024repo stars cypress-defect-tracking-cursorrules-prompt-file A Cursor rule that turns the agent into a QA engineer: writes Cypress tests tagged by team, category and case ID, and builds reports through qa-shadow-report. ★ 41,024repo stars cypress-api-testing-cursorrules-prompt-file Configures Cursor to write Cypress API tests with schema validation. It detects TypeScript in the project and validates responses using cypress-ajv-schema-validator. ★ 41,024repo stars cypress-accessibility-testing-cursorrules-prompt-file A Cursor rule for writing Cypress accessibility tests covering WCAG checks, keyboard paths, ARIA, focus, and screen-reader behavior. ★ 41,024repo stars cursorrules-cursor-ai-wordpress-draft-macos-prompt A Cursor rule that describes the PressThat project: a system tray app that connects to WordPress and creates draft posts. Useful if you work on that app in Cursor. ★ 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