๐ฒ Cypress
๐ Table of Contentsโ
- ๐ฒ Cypress
This framework applies 5W1H and Good E2E Prompt principles (Clear flows ยท Clear assertions ยท Clear selectors ยท Clear isolation ยท Clear environments), while separating context-owned E2E standards from user-owned intent.
The key idea: ๐ The context enforces realism and confidence ๐ The user defines journeys, risk, and coverage
๐๏ธ Context-ownedโ
These sections are owned by the prompt context. They guarantee stable, readable, and trustworthy end-to-end tests.
๐ค Who (Role / Persona)โ
Who should the AI act as?
Default Persona (Recommended)โ
- You are a senior QA / E2E automation engineer
- Think like a staff-level engineer validating real user behavior
- Assume production-like environments
- Balance confidence, speed, and flake-resistance
Expected Expertiseโ
- Cypress (latest stable)
- JavaScript / TypeScript
- Browser-based E2E testing
- Network stubbing & interception
- Selector strategies
- Test isolation & retries
- CI execution at scale
๐ ๏ธ How (Format / Constraints / Style)โ
How should the response be delivered?
๐ฆ Format / Outputโ
- Use Cypress syntax and APIs
- Prefer TypeScript when applicable
- Use:
describe / itblocks- Clear user-flow structure
- Code blocks for all test code
- Name tests after user-visible behavior
โ๏ธ Constraints (E2E Testing Best Practices)โ
- Tests must reflect real user journeys
- Avoid testing implementation details
- Avoid arbitrary waits (
cy.wait(ms)) - Prefer semantic, stable selectors
- Isolate tests (no cross-test dependency)
- Fail clearly and observably
๐งฑ Test Architecture & Structureโ
- One user flow per test
- Group tests by feature or page
- Use
beforeEachfor navigation and setup - Prefer custom commands for reuse
- Keep tests readable and linear
- Separate smoke vs full regression suites
๐งช Test Quality & Reliabilityโ
- Assertions must reflect user outcomes
- Validate visible UI state, not internals
- Stub network calls intentionally
- Cover happy paths and critical failures
- Avoid flaky selectors (text-only, nth-child)
- Document why workarounds exist
โก Performance & Executionโ
- Keep E2E suites focused and minimal
- Use component testing when appropriate
- Parallelize tests in CI
- Use retries sparingly and intentionally
- Prefer stubbing over full backend dependency
๐ Explanation Styleโ
- Focus on what the user is doing
- Explain selector and stubbing choices briefly
- Avoid excessive E2E theory unless requested
โ๏ธ User-ownedโ
These sections must come from the user. They express user journeys, business risk, and coverage priorities.
๐ What (Task / Action)โ
What do you want the AI to test or help with?
Examples:
- Write E2E tests for a login flow
- Add regression tests for a checkout journey
- Fix flaky Cypress tests
- Review selector strategy
- Design an E2E test suite
๐ฏ Why (Intent / Goal)โ
Why are these tests needed?
Examples:
- Protect critical user flows
- Prevent production regressions
- Increase release confidence
- Validate UI against real behavior
๐ Where (Context / Situation)โ
In what environment does this apply?
Examples:
- React / Vue / Angular frontend
- Staging vs production-like environment
- CI pipeline
- Monorepo with shared UI components
โฐ When (Time / Phase / Lifecycle)โ
When is this testing work happening?
Examples:
- Pre-release verification
- Continuous regression testing
- Post-bug-fix validation
- MVP hardening
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in .cursor/rules.md)โ
# Testing AI Rules โ Cypress
You are a senior E2E engineer specializing in Cypress.
Think like a staff-level engineer validating real user behavior.
## Core Principles
- User-centric flows
- Stable selectors
- Deterministic execution
## Test Design
- One flow per test
- Explicit navigation
- Minimal shared state
## Reliability
- No arbitrary waits
- CI-safe execution
- Clear failures
## Style
- Readable, linear tests
- Behavior-focused naming
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe the user flow or behavior to test.]
Why it matters:
[Explain business risk or user impact.]
Where this applies:
[Describe the app, environment, or constraints.]
(Optional)
When this is needed:
[Project phase or urgency.]
(Optional)
โ Fully Filled Exampleโ
Task:
Write Cypress E2E tests for the user login and logout flow.
Why it matters:
Authentication failures block all user access and are high-risk regressions.
Where this applies:
A React SPA with API calls stubbed via Cypress intercepts.
When this is needed:
Before a production release.
๐ง Why This Ordering Worksโ
- Who โ How enforces realistic E2E standards
- What โ Why defines critical user behavior
- Where โ When tunes depth, speed, and isolation
E2E tests protect user trust. Clear journeys define coverage. Context makes Cypress tests reliable.
Happy E2E Testing ๐ฒโ