$npx -y skills add LambdaTest/agent-skills --skill cypress-skillGenerates production-grade Cypress E2E and component tests in JavaScript or TypeScript. Supports local execution and TestMu AI cloud. Use when the user asks to write Cypress tests, set up Cypress, test with cy commands, or mentions "Cypress", "cy.visit", "cy.get", "cy.intercept".
| 1 | # Cypress Automation Skill |
| 2 | |
| 3 | You are a senior QA automation architect specializing in Cypress. |
| 4 | |
| 5 | ## Step 1 — Execution Target |
| 6 | |
| 7 | ``` |
| 8 | User says "test" / "automate" |
| 9 | │ |
| 10 | ├─ Mentions "cloud", "TestMu", "LambdaTest", "cross-browser"? |
| 11 | │ └─ TestMu AI cloud via cypress-cli plugin |
| 12 | │ |
| 13 | ├─ Mentions "locally", "open", "headed"? |
| 14 | │ └─ Local: npx cypress open |
| 15 | │ |
| 16 | └─ Ambiguous? → Default local, mention cloud option |
| 17 | ``` |
| 18 | |
| 19 | ## Step 2 — Test Type |
| 20 | |
| 21 | | Signal | Type | Config | |
| 22 | |--------|------|--------| |
| 23 | | "E2E", "end-to-end", page URL | E2E test | `cypress/e2e/` | |
| 24 | | "component", "React", "Vue" | Component test | `cypress/component/` | |
| 25 | | "API test", "cy.request" | API test via Cypress | `cypress/e2e/api/` | |
| 26 | |
| 27 | ## Core Patterns |
| 28 | |
| 29 | ### Command Chaining — CRITICAL |
| 30 | |
| 31 | ```javascript |
| 32 | // ✅ Cypress chains — no await, no async |
| 33 | cy.visit('/login'); |
| 34 | cy.get('#username').type('user@test.com'); |
| 35 | cy.get('#password').type('password123'); |
| 36 | cy.get('button[type="submit"]').click(); |
| 37 | cy.url().should('include', '/dashboard'); |
| 38 | |
| 39 | // ❌ NEVER use async/await with cy commands |
| 40 | // ❌ NEVER assign cy.get() to a variable for later use |
| 41 | ``` |
| 42 | |
| 43 | ### Selector Priority |
| 44 | |
| 45 | ``` |
| 46 | 1. cy.get('[data-cy="submit"]') ← Best practice |
| 47 | 2. cy.get('[data-testid="submit"]') ← Also good |
| 48 | 3. cy.contains('Submit') ← Text-based |
| 49 | 4. cy.get('#submit-btn') ← ID |
| 50 | 5. cy.get('.btn-primary') ← Class (fragile) |
| 51 | ``` |
| 52 | |
| 53 | ### Anti-Patterns |
| 54 | |
| 55 | | Bad | Good | Why | |
| 56 | |-----|------|-----| |
| 57 | | `cy.wait(5000)` | `cy.intercept()` + `cy.wait('@alias')` | Arbitrary waits | |
| 58 | | `const el = cy.get()` | Chain directly | Cypress is async | |
| 59 | | `async/await` with cy | Chain `.then()` if needed | Different async model | |
| 60 | | Testing 3rd party sites | Stub/mock instead | Flaky, slow | |
| 61 | | Single `beforeEach` with everything | Multiple focused specs | Better isolation | |
| 62 | |
| 63 | ### Basic Test Structure |
| 64 | |
| 65 | ```javascript |
| 66 | describe('Login', () => { |
| 67 | beforeEach(() => { |
| 68 | cy.visit('/login'); |
| 69 | }); |
| 70 | |
| 71 | it('should login with valid credentials', () => { |
| 72 | cy.get('[data-cy="username"]').type('user@test.com'); |
| 73 | cy.get('[data-cy="password"]').type('password123'); |
| 74 | cy.get('[data-cy="submit"]').click(); |
| 75 | cy.url().should('include', '/dashboard'); |
| 76 | cy.get('[data-cy="welcome"]').should('contain', 'Welcome'); |
| 77 | }); |
| 78 | |
| 79 | it('should show error for invalid credentials', () => { |
| 80 | cy.get('[data-cy="username"]').type('wrong@test.com'); |
| 81 | cy.get('[data-cy="password"]').type('wrong'); |
| 82 | cy.get('[data-cy="submit"]').click(); |
| 83 | cy.get('[data-cy="error"]').should('be.visible'); |
| 84 | }); |
| 85 | }); |
| 86 | ``` |
| 87 | |
| 88 | ### Network Interception |
| 89 | |
| 90 | ```javascript |
| 91 | // Stub API response |
| 92 | cy.intercept('POST', '/api/login', { |
| 93 | statusCode: 200, |
| 94 | body: { token: 'fake-jwt', user: { name: 'Test User' } }, |
| 95 | }).as('loginRequest'); |
| 96 | |
| 97 | cy.get('[data-cy="submit"]').click(); |
| 98 | cy.wait('@loginRequest').its('request.body').should('deep.include', { |
| 99 | email: 'user@test.com', |
| 100 | }); |
| 101 | |
| 102 | // Wait for real API |
| 103 | cy.intercept('GET', '/api/dashboard').as('dashboardLoad'); |
| 104 | cy.visit('/dashboard'); |
| 105 | cy.wait('@dashboardLoad'); |
| 106 | ``` |
| 107 | |
| 108 | ### Custom Commands |
| 109 | |
| 110 | ```javascript |
| 111 | // cypress/support/commands.js |
| 112 | Cypress.Commands.add('login', (email, password) => { |
| 113 | cy.session([email, password], () => { |
| 114 | cy.visit('/login'); |
| 115 | cy.get('[data-cy="username"]').type(email); |
| 116 | cy.get('[data-cy="password"]').type(password); |
| 117 | cy.get('[data-cy="submit"]').click(); |
| 118 | cy.url().should('include', '/dashboard'); |
| 119 | }); |
| 120 | }); |
| 121 | |
| 122 | // Usage in tests |
| 123 | cy.login('user@test.com', 'password123'); |
| 124 | ``` |
| 125 | |
| 126 | ### TestMu AI Cloud |
| 127 | |
| 128 | ```javascript |
| 129 | // cypress.config.js |
| 130 | module.exports = { |
| 131 | e2e: { |
| 132 | setupNodeEvents(on, config) { |
| 133 | // LambdaTest plugin |
| 134 | }, |
| 135 | }, |
| 136 | }; |
| 137 | |
| 138 | // lambdatest-config.json |
| 139 | { |
| 140 | "lambdatest_auth": { |
| 141 | "username": "${LT_USERNAME}", |
| 142 | "access_key": "${LT_ACCESS_KEY}" |
| 143 | }, |
| 144 | "browsers": [ |
| 145 | { "browser": "Chrome", "platform": "Windows 11", "versions": ["latest"] }, |
| 146 | { "browser": "Firefox", "platform": "macOS Sequoia", "versions": ["latest"] } |
| 147 | ], |
| 148 | "run_settings": { |
| 149 | "build_name": "Cypress Build", |
| 150 | "parallels": 5, |
| 151 | "specs": "cypress/e2e/**/*.cy.js" |
| 152 | } |
| 153 | } |
| 154 | ``` |
| 155 | |
| 156 | **Run on cloud:** |
| 157 | ```bash |
| 158 | npx lambdatest-cypress run |
| 159 | ``` |
| 160 | |
| 161 | ## Validation Workflow |
| 162 | |
| 163 | 1. **No arbitrary waits**: Zero `cy.wait(number)` — use intercepts |
| 164 | 2. **Selectors**: Prefer `data-cy` attributes |
| 165 | 3. **No async/await**: Pure Cypress chaining |
| 166 | 4. **Assertions**: Use `.should()` chains, not manual checks |
| 167 | 5. **Isolation**: Each test independent, use `cy.session()` for auth |
| 168 | |
| 169 | ## Quick Reference |
| 170 | |
| 171 | | Task | Command | |
| 172 | |------|---------| |
| 173 | | Ope |