QA Cypress Writer
Purpose
Write Cypress E2E and component tests from test case specifications. Transform structured test cases into executable TypeScript test files with proper selectors, network mocking, and component isolation.
Trigger Phrases
- "Write Cypress tests for [feature/page]"
- "Generate Cypress E2E tests from test cases"
- "Create Cypress component tests for [component]"
- "Add Cypress tests with cy.intercept for [API]"
- "Cypress tests with cy.mount for [React/Vue component]"
- "Cypress E2E test file for [flow]"
- "Cypress custom commands for [login/fillForm]"
Test Types
| Type |
Scope |
When to Use |
| E2E |
Full user flows, page navigation |
Critical paths, user journeys |
| Component |
Isolated UI components |
React/Vue/Angular/Svelte components |
Workflow
- Read test cases — From Phase 2 (qa-testcase-from-docs, qa-manual-test-designer, qa-browser-data-collector)
- Analyze target — Page structure, API endpoints, component props/events
- Generate test files — Create
*.cy.ts in cypress/e2e/ or cypress/component/
- Add intercepts/fixtures —
cy.intercept(), cy.fixture() for network control
- Verify selectors — Prefer
data-cy attributes; avoid brittle CSS
Context7 MCP
Uses Context7 MCP to fetch current Cypress documentation when needed. Query for Cypress API, commands, or configuration when patterns are unclear.
E2E Testing
- Navigation:
cy.visit(), cy.go(), cy.reload()
- Queries:
cy.get(), cy.contains(), cy.find() — chainable, retry-able
- Actions:
cy.click(), cy.type(), cy.clear(), cy.select(), cy.check()
- Chained commands — Each command retries until timeout; enables time-travel debugging
- Retry-ability — Cypress automatically retries assertions and queries
Component Testing
- cy.mount() — Mount React/Vue/Angular/Svelte components in isolation
- Props/events/slots — Test component behavior without full app
- Dev server — Uses
component.devServer in config (Vite, Webpack, etc.)
Network Mocking
- cy.intercept() — Stub, spy, or wait for HTTP requests
- Fixtures —
cy.fixture() for response data; cy.intercept('GET', '/api/users', { fixture: 'users.json' })
- Aliases —
cy.intercept('GET', '/api/users').as('getUsers'); cy.wait('@getUsers')
Custom Commands
- Cypress.Commands.add() — Reusable actions:
cy.login(), cy.fillForm(), cy.logout()
- Declare in cypress/support/commands.ts — Extend Cypress namespace for TypeScript
Key Patterns
- Structure:
describe / it, beforeEach / afterEach
- Auth:
cy.session() for login state caching (Cypress 8+)
- Screenshots:
cy.screenshot() for debugging; auto on failure
- Data attributes:
data-cy="submit-btn" for stable selectors
- Assertions: Explicit
should() / expect(); avoid implicit passes
Configuration
- cypress.config.ts —
baseUrl, viewportWidth/viewportHeight, video, retries, component.devServer
- Support files —
cypress/support/e2e.ts, commands.ts
See references/config.md for full configuration guide.
File Naming
cypress/e2e/{feature}.cy.ts — E2E tests
cypress/component/{Component}.cy.tsx — Component tests
References
references/patterns.md — E2E flows, component mounting, custom commands, fixtures, aliases
references/assertions.md — should, expect, assert patterns (Chai)
references/config.md — cypress.config.ts, env, plugins, support files
references/best-practices.md — data-cy, anti-patterns, flake prevention, CI
Scope
Can do (autonomous):
- Generate Cypress E2E and component tests from test cases
- Add
cy.intercept() for API stubbing/spying
- Create custom commands in
commands.ts
- Use
cy.fixture() and cy.session() where appropriate
- Configure
cypress.config.ts for baseUrl, viewport, retries
- Add
data-cy selectors in generated tests (recommend adding to app if missing)
Cannot do (requires confirmation):
- Modify production code to add
data-cy attributes
- Change existing Cypress config without user approval
- Add tests for flows/components not in scope
Will not do (out of scope):
- Unit tests (use qa-jest-writer)
- Visual regression (use dedicated tools)
- Modify application deployment or runtime
Quality Checklist
Troubleshooting
| Symptom |
Likely Cause |
Fix |
| Element not found |
Selector too brittle or timing |
Use data-cy; ensure element exists before action; increase timeout if needed |
| cy.wait(ms) flakiness |
Arbitrary delays |
Replace with cy.wait('@alias') or should() assertions |
| Intercept not matching |
URL/pattern mismatch |
Use cy.intercept('**/api/users*') or exact URL; check method |
| Session not persisting |
cy.session misconfigured |
Ensure cy.session() in beforeEach; validate cache key |
| Component mount fails |
Missing provider/wrapper |
Add providers in cy.mount(<Provider><Component /></Provider>) |
| Cross-origin errors |
Navigating to different domain |
Use cy.origin() for cross-origin flows |
| Timeout on assertion |
Element never meets condition |
Verify selector; check if element is in iframe (not supported) |
1---2name: qa-cypress-writer3description: Generate Cypress E2E and component tests for TypeScript with time-travel debugging, cy.intercept for network mocking, and component testing via cy.mount.4---56# QA Cypress Writer78## Purpose910Write Cypress E2E and component tests from test case specifications. Transform structured test cases into executable TypeScript test files with proper selectors, network mocking, and component isolation.1112## Trigger Phrases1314- "Write Cypress tests for [feature/page]"15- "Generate Cypress E2E tests from test cases"16- "Create Cypress component tests for [component]"17- "Add Cypress tests with cy.intercept for [API]"18- "Cypress tests with cy.mount for [React/Vue component]"19- "Cypress E2E test file for [flow]"20- "Cypress custom commands for [login/fillForm]"2122## Test Types2324| Type | Scope | When to Use |25|------|-------|-------------|26| **E2E** | Full user flows, page navigation | Critical paths, user journeys |27| **Component** | Isolated UI components | React/Vue/Angular/Svelte components |2829## Workflow30311. **Read test cases** — From Phase 2 (qa-testcase-from-docs, qa-manual-test-designer, qa-browser-data-collector)322. **Analyze target** — Page structure, API endpoints, component props/events333. **Generate test files** — Create `*.cy.ts` in `cypress/e2e/` or `cypress/component/`344. **Add intercepts/fixtures** — `cy.intercept()`, `cy.fixture()` for network control355. **Verify selectors** — Prefer `data-cy` attributes; avoid brittle CSS3637## Context7 MCP3839Uses Context7 MCP to fetch current Cypress documentation when needed. Query for Cypress API, commands, or configuration when patterns are unclear.4041## E2E Testing4243- **Navigation:** `cy.visit()`, `cy.go()`, `cy.reload()`44- **Queries:** `cy.get()`, `cy.contains()`, `cy.find()` — chainable, retry-able45- **Actions:** `cy.click()`, `cy.type()`, `cy.clear()`, `cy.select()`, `cy.check()`46- **Chained commands** — Each command retries until timeout; enables time-travel debugging47- **Retry-ability** — Cypress automatically retries assertions and queries4849## Component Testing5051- **cy.mount()** — Mount React/Vue/Angular/Svelte components in isolation52- **Props/events/slots** — Test component behavior without full app53- **Dev server** — Uses `component.devServer` in config (Vite, Webpack, etc.)5455## Network Mocking5657- **cy.intercept()** — Stub, spy, or wait for HTTP requests58- **Fixtures** — `cy.fixture()` for response data; `cy.intercept('GET', '/api/users', { fixture: 'users.json' })`59- **Aliases** — `cy.intercept('GET', '/api/users').as('getUsers')`; `cy.wait('@getUsers')`6061## Custom Commands6263- **Cypress.Commands.add()** — Reusable actions: `cy.login()`, `cy.fillForm()`, `cy.logout()`64- **Declare in cypress/support/commands.ts** — Extend Cypress namespace for TypeScript6566## Key Patterns6768- **Structure:** `describe` / `it`, `beforeEach` / `afterEach`69- **Auth:** `cy.session()` for login state caching (Cypress 8+)70- **Screenshots:** `cy.screenshot()` for debugging; auto on failure71- **Data attributes:** `data-cy="submit-btn"` for stable selectors72- **Assertions:** Explicit `should()` / `expect()`; avoid implicit passes7374## Configuration7576- **cypress.config.ts** — `baseUrl`, `viewportWidth`/`viewportHeight`, `video`, `retries`, `component.devServer`77- **Support files** — `cypress/support/e2e.ts`, `commands.ts`7879See `references/config.md` for full configuration guide.8081## File Naming8283- `cypress/e2e/{feature}.cy.ts` — E2E tests84- `cypress/component/{Component}.cy.tsx` — Component tests8586## References8788- `references/patterns.md` — E2E flows, component mounting, custom commands, fixtures, aliases89- `references/assertions.md` — should, expect, assert patterns (Chai)90- `references/config.md` — cypress.config.ts, env, plugins, support files91- `references/best-practices.md` — data-cy, anti-patterns, flake prevention, CI9293## Scope9495**Can do (autonomous):**96- Generate Cypress E2E and component tests from test cases97- Add `cy.intercept()` for API stubbing/spying98- Create custom commands in `commands.ts`99- Use `cy.fixture()` and `cy.session()` where appropriate100- Configure `cypress.config.ts` for baseUrl, viewport, retries101- Add `data-cy` selectors in generated tests (recommend adding to app if missing)102103**Cannot do (requires confirmation):**104- Modify production code to add `data-cy` attributes105- Change existing Cypress config without user approval106- Add tests for flows/components not in scope107108**Will not do (out of scope):**109- Unit tests (use qa-jest-writer)110- Visual regression (use dedicated tools)111- Modify application deployment or runtime112113## Quality Checklist114115- [ ] No `cy.wait(ms)` — use `cy.wait('@alias')` or assertions instead116- [ ] Use `data-cy` attributes for selectors where possible117- [ ] Assertions explicit — every meaningful step has assertion118- [ ] No cross-test dependencies — tests run in any order119- [ ] Proper cleanup — no leftover state between tests120- [ ] Intercepts scoped — avoid global intercepts that leak121- [ ] Descriptive test names — "should display error when login fails"122123## Troubleshooting124125| Symptom | Likely Cause | Fix |126|---------|--------------|-----|127| Element not found | Selector too brittle or timing | Use `data-cy`; ensure element exists before action; increase timeout if needed |128| cy.wait(ms) flakiness | Arbitrary delays | Replace with `cy.wait('@alias')` or `should()` assertions |129| Intercept not matching | URL/pattern mismatch | Use `cy.intercept('**/api/users*')` or exact URL; check method |130| Session not persisting | cy.session misconfigured | Ensure `cy.session()` in `beforeEach`; validate cache key |131| Component mount fails | Missing provider/wrapper | Add providers in `cy.mount(<Provider><Component /></Provider>)` |132| Cross-origin errors | Navigating to different domain | Use `cy.origin()` for cross-origin flows |133| Timeout on assertion | Element never meets condition | Verify selector; check if element is in iframe (not supported) |