Home › Testing › Cypress end-to-end testing AGENTS.md

Cypress end-to-end testing AGENTS.md

AGENTS.md for Cypress 15 E2E and component tests: selectors, cy.intercept, sessions, and flake-free waits.

AGENTS.mdTesting

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: Cypress tests

## Commands
- Headless: `npx cypress run` · one spec: `npx cypress run --spec cypress/e2e/checkout.cy.ts` · component tests: `npx cypress run --component`
- Interactive (for humans): `npx cypress open`

## Writing tests
- Specs in `cypress/e2e/<feature>.cy.ts`; component specs next to components (`Button.cy.tsx`).
- Select by `data-cy` attributes (`cy.get('[data-cy=submit]')`) or accessible text via `cy.contains('button', 'Pay')`. Never select by CSS classes or DOM structure.
- Cypress commands are async and chain; don't assign their results to variables. Use `.then()` or aliases (`.as('order')`).
- Assertions retry: `cy.get(...).should('have.text', 'Paid')`. Never `cy.wait(5000)`; wait on aliased network calls instead: `cy.intercept('POST', '/api/orders').as('createOrder'); ... cy.wait('@createOrder')`.
- Stub third-party and slow services with `cy.intercept` + fixtures; keep at least one happy-path test against the real backend.
- Log in with `cy.session()` + an API request in a custom command (`cy.login()`), not through the UI each time.
- Seed and reset data with `cy.task('db:seed')` or API calls in `beforeEach`; tests must not depend on each other.
- Custom commands live in `cypress/support/commands.ts` with TypeScript declarations.

## Don't
- Don't use `{ force: true }` to click hidden elements, or `cy.wait(<ms>)`.
- Don't disable `testIsolation`.

## Done
The changed specs pass headless 3 times in a row.

More: all Testing rules · all AGENTS.md rules

Related rules

Jest testing rules

Cursor rules for Jest 30 test suites in TypeScript: structure, mocking boundaries, timers, and async tests.

CursorTesting

Playwright end-to-end testing rules

Cursor rules for Playwright Test (TypeScript): resilient locators, web-first assertions, fixtures, and no flaky waits.

CursorTesting

pytest testing CLAUDE.md

CLAUDE.md for Python test suites with pytest 8: fixtures, parametrize, mocking boundaries, and coverage.

Claude Code (CLAUDE.md)Testing

Test runner subagent (Claude Code)

A Claude Code subagent that runs the right tests for a change, diagnoses failures, and proposes minimal fixes.

Claude Code (CLAUDE.md)Testing

Test files Copilot path instructions

Path-specific Copilot instructions applied to test files in any language: structure, determinism, and no cheating.

GitHub CopilotTesting

Vitest unit testing AGENTS.md

AGENTS.md for unit and component tests with Vitest 3 and Testing Library in Vite/TypeScript projects.

AGENTS.mdTesting

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.