Cursor rule
frameworks/cypress/.cursor/rules/cypress-excellence.mdcAdvanced Cypress testing patterns and best practices — custom commands, page objects, and network testing
Cursor rules
Quality
58/100
Scores the file, not the repository.Length
630 words
10 headings · 7 code blocksRepository
18
— · pushed 0 days agoLast changed
2 days ago
First indexed 2 days ago.123456# Cypress Testing Excellence78## Modern Framework Architecture9- **TypeScript Integration**: Full TypeScript support with intelligent intellisense10- **Component Testing**: Isolated component testing alongside E2E scenarios11- **Advanced Page Objects**: Modular page object patterns with inheritance12- **Smart Fixture Management**: Dynamic test data with environment-aware loading1314## Element Selection Revolution15```javascript16// Modern approach: Reliable, maintainable selectors17cy.get('[data-cy=user-dashboard]') // Preferred: Test-specific attributes18 .find('[data-cy=profile-section]') // Hierarchical selection19 .within(() => { // Scoped interactions20 cy.get('[data-cy=edit-button]').click()21 })2223// Avoid: Brittle selectors that break with UI changes24// cy.get('.btn.btn-primary.user-btn') // CSS classes25// cy.get('#user-123-edit') // Dynamic IDs26```2728## Advanced Custom Commands29```javascript30// Example: Intelligent login command with session management31Cypress.Commands.add('loginAs', (userType, options = {}) => {32 const { persist = true, skipWelcome = true } = options3334 cy.session(userType, () => {35 cy.visit('/login')36 cy.fixture(`users/${userType}`).then(user => {37 cy.get('[data-cy=email-input]').type(user.email)38 cy.get('[data-cy=password-input]').type(user.password)39 cy.get('[data-cy=login-button]').click()4041 // Wait for successful authentication42 cy.url().should('include', '/dashboard')43 cy.get('[data-cy=user-avatar]').should('be.visible')44 })45 }, {46 validate: () => {47 // Verify session is still valid48 cy.getCookie('auth-token').should('exist')49 },50 cacheAcrossSpecs: persist51 })5253 if (skipWelcome) {54 cy.dismissWelcomeModal()55 }56})57```5859## Network Testing Mastery60```javascript61// Example: Comprehensive API testing with validation62it('should handle user creation workflow', () => {63 // Set up network intercepts64 cy.intercept('POST', '/api/users', {65 statusCode: 201,66 body: { id: 'user-123', status: 'created' }67 }).as('createUser')6869 cy.intercept('GET', '/api/users/user-123', {70 fixture: 'user-profile.json'71 }).as('getUserProfile')7273 // Perform user actions74 cy.visit('/users/new')75 cy.fillUserForm({76 name: 'John Doe',77 email: 'john@example.com',78 role: 'admin'79 })80 cy.get('[data-cy=submit-button]').click()8182 // Validate network interactions83 cy.wait('@createUser').then(interception => {84 expect(interception.request.body).to.deep.include({85 name: 'John Doe',86 email: 'john@example.com'87 })88 })8990 cy.wait('@getUserProfile')91 cy.get('[data-cy=success-message]').should('contain', 'User created successfully')92})93```9495## Modern Test Organization96```javascript97// Example: Feature-based test organization with proper setup98describe('User Management Feature', () => {99 beforeEach(() => {100 // Environment-aware setup101 cy.setupTestEnvironment()102 cy.loginAs('admin')103 cy.navigateToUserManagement()104 })105106 context('User Creation', () => {107 it('should create user with valid data', { tags: ['@smoke', '@user-management'] }, () => {108 cy.createUser({109 name: 'Test User',110 email: 'test@example.com',111 permissions: ['read', 'write']112 })113114 cy.verifyUserExists('test@example.com')115 cy.verifyUserPermissions('test@example.com', ['read', 'write'])116 })117118 it('should validate required fields', { tags: ['@validation'] }, () => {119 cy.get('[data-cy=create-user-button]').click()120 cy.get('[data-cy=submit-button]').click()121122 cy.get('[data-cy=name-error]').should('contain', 'Name is required')123 cy.get('[data-cy=email-error]').should('contain', 'Email is required')124 })125 })126127 context('User Permissions', () => {128 beforeEach(() => {129 cy.createTestUser('permissions-test-user')130 })131132 it('should update user permissions', { tags: ['@permissions'] }, () => {133 cy.editUserPermissions('permissions-test-user', {134 add: ['admin'],135 remove: ['read']136 })137138 cy.verifyUserPermissions('permissions-test-user', ['write', 'admin'])139 })140 })141})142```143144## Performance & Reliability Optimization145```javascript146// Example: Optimized waiting strategies147Cypress.Commands.add('waitForStableDOM', (selector, options = {}) => {148 const { timeout = 10000, interval = 100 } = options149150 cy.get(selector, { timeout }).should('be.visible').then($el => {151 const initialRect = $el[0].getBoundingClientRect()152153 cy.wait(interval).then(() => {154 cy.get(selector).then($newEl => {155 const newRect = $newEl[0].getBoundingClientRect()156157 if (initialRect.x !== newRect.x || initialRect.y !== newRect.y) {158 cy.waitForStableDOM(selector, options) // Recursive wait159 }160 })161 })162 })163})164165// Usage in tests166cy.waitForStableDOM('[data-cy=dynamic-content]')167 .click() // Safe to interact after DOM is stable168```169170## Visual & Accessibility Testing171```javascript172// Example: Comprehensive visual regression testing173it('should maintain visual consistency', () => {174 cy.visit('/dashboard')175 cy.loginAs('standard-user')176177 // Wait for all content to load178 cy.get('[data-cy=dashboard-content]').should('be.visible')179 cy.waitForSkeletonLoading()180181 // Visual regression test182 cy.compareSnapshot('dashboard-layout', {183 threshold: 0.02,184 thresholdType: 'percent'185 })186187 // Accessibility validation188 cy.checkA11y('[data-cy=main-content]', {189 runOnly: {190 type: 'tag',191 values: ['wcag2a', 'wcag2aa']192 }193 })194})195```196197## CI/CD Integration Excellence198```javascript199// cypress.config.js - Environment-aware configuration200module.exports = defineConfig({201 e2e: {202 baseUrl: process.env.CYPRESS_BASE_URL || 'http://localhost:3000',203 supportFile: 'cypress/support/e2e.js',204 specPattern: 'cypress/e2e/**/*.cy.{js,ts}',205206 // Advanced configuration207 viewportWidth: 1280,208 viewportHeight: 720,209 video: process.env.CI,210 screenshotOnRunFailure: true,211212 // Performance optimizations213 numTestsKeptInMemory: 0,214 experimentalMemoryManagement: true,215216 setupNodeEvents(on, config) {217 // Plugin configuration218 require('cypress-terminal-report/src/installLogsPrinter')(on)219 require('@cypress/code-coverage/task')(on, config)220221 // Environment-specific setup222 config.env = {223 ...config.env,224 ...process.env225 }226227 return config228 }229 },230231 component: {232 devServer: {233 framework: 'react',234 bundler: 'webpack'235 },236 specPattern: 'src/**/*.cy.{js,ts,jsx,tsx}'237 }238})239```240241## Advanced Debugging & Maintenance242- **Comprehensive Logging**: Detailed command logging with context243- **Failure Analysis**: Automatic screenshot and video capture with timeline244- **Performance Monitoring**: Test execution metrics and optimization recommendations245- **Parallel Execution**: Intelligent test distribution across CI/CD pipeline stages246
Also in tugkanboz/awesome-cursorrules
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| tugkanboz/awesome-cursorrulesexample-structures/cypress/.cursor/rules/api-testing.mdc · 18 | Cursor rules | testtesting-strategyapi | 58/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/cypress/.cursor/rules/testing-fundamentals.mdc · 18 | Cursor rules | testarchtesting-strategysecurity+2 | 62/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/appium-mobile-test-automation-framework/.cursorrules · 18 | .cursorrules | teststylearchperformance+2 | 56/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/cypress-javascript-test-automation-framework/.cursorrules · 18 | .cursorrules | testlint-formatstylearch+4 | 59/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/k6-performance-test-framework/.cursorrules · 18 | .cursorrules | setupteststylearch+2 | 56/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/restassured-java-framework/.cursorrules · 18 | .cursorrules | teststylearchsecurity+4 | 56/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/selenium-net-test-automation-framework/.cursorrules · 18 | .cursorrules | teststylearchdeployment+1 | 56/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/selenium-python-test-automation-framework/.cursorrules · 18 | .cursorrules | testlint-formatstylearch+3 | 59/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/webdriverio-javascript-test-automation-framework/.cursorrules · 18 | .cursorrules | testlint-formatstylearch+4 | 69/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/next-js/.cursor/rules/app-router-patterns.mdc · 18 | Cursor rules | styleapido-not | 65/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/react-typescript/.cursor/rules/component-development.mdc · 18 | Cursor rules | teststylearchtypes+1 | 58/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/selenium-python/.cursor/rules/framework-architecture.mdc · 18 | Cursor rules | setuptestlint-formatstyle+3 | 93/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/selenium-python/.cursor/rules/page-object-patterns.mdc · 18 | Cursor rules | ui | 54/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesexample-structures/selenium-python/.cursor/rules/test-patterns.mdc · 18 | Cursor rules | teststylearchtesting-strategy+1 | 66/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/playwright-javascript-test-automation-framework/.cursorrules · 18 | .cursorrules | testlint-formatstylearch+3 | 59/100 | 2 days ago | |
| tugkanboz/awesome-cursorrulesrules/vitest-javascript-unit-test-framework/.cursorrules · 18 | .cursorrules | setupteststylearch+5 | 60/100 | 2 days ago |
Diff against example-structures/cypress/.cursor/rules/api-testing.mdc Diff against example-structures/cypress/.cursor/rules/testing-fundamentals.mdc Diff against rules/appium-mobile-test-automation-framework/.cursorrules Diff against rules/cypress-javascript-test-automation-framework/.cursorrules Diff against rules/k6-performance-test-framework/.cursorrules Diff against rules/restassured-java-framework/.cursorrules Diff against rules/selenium-net-test-automation-framework/.cursorrules Diff against rules/selenium-python-test-automation-framework/.cursorrules Diff against rules/webdriverio-javascript-test-automation-framework/.cursorrules Diff against example-structures/next-js/.cursor/rules/app-router-patterns.mdc Diff against example-structures/react-typescript/.cursor/rules/component-development.mdc Diff against example-structures/selenium-python/.cursor/rules/framework-architecture.mdc Diff against example-structures/selenium-python/.cursor/rules/page-object-patterns.mdc Diff against example-structures/selenium-python/.cursor/rules/test-patterns.mdc Diff against rules/playwright-javascript-test-automation-framework/.cursorrules Diff against rules/vitest-javascript-unit-test-framework/.cursorrules
