0
0
Cypresstesting~8 mins

Skipping and focusing tests (.skip, .only) in Cypress - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Skipping and focusing tests (.skip, .only)
Folder Structure for Cypress Test Framework
cypress/
├── e2e/                  # Test files (specs) go here
│   ├── login.spec.js     # Example test file
│   └── dashboard.spec.js
├── fixtures/             # Test data files (JSON, etc.)
│   └── users.json
├── support/              # Support files and commands
│   ├── commands.js       # Custom commands
│   └── e2e.js            # Global setup
cypress.config.js         # Cypress configuration file
package.json              # Project dependencies and scripts
Test Framework Layers in Cypress
  • Test Layer (cypress/e2e): Contains test files where you write your test cases using describe and it. Here you use .skip and .only to control which tests run.
  • Support Layer (cypress/support): Contains reusable commands and global setup to keep tests clean.
  • Fixtures Layer (cypress/fixtures): Holds test data files to separate data from test logic.
  • Configuration Layer (cypress.config.js): Defines environment settings, base URLs, and browser options.
Configuration Patterns for Skipping and Focusing Tests

Use .skip and .only directly in test files to control test execution:

  • describe.skip('Feature', () => { ... }) skips all tests in this group.
  • it.skip('should do something', () => { ... }) skips a single test.
  • describe.only('Feature', () => { ... }) runs only this group, skipping others.
  • it.only('should do something', () => { ... }) runs only this test.

Use environment variables in cypress.config.js or package.json scripts to control which tests run dynamically if needed.

Test Reporting and CI/CD Integration
  • Use Cypress built-in reporters or plugins like mochawesome for detailed reports.
  • Configure CI/CD pipelines (GitHub Actions, Jenkins, etc.) to run tests with commands like npx cypress run.
  • Ensure skipped tests are reported clearly to avoid confusion.
  • Use focused tests (.only) carefully to avoid missing test coverage in CI.
Best Practices for Skipping and Focusing Tests
  1. Use .skip to temporarily disable flaky or incomplete tests but remove skips before final commits.
  2. Use .only locally to focus on debugging but never commit .only to shared branches.
  3. Keep skipped tests documented with comments explaining why they are skipped.
  4. Use environment variables or tags for conditional test runs instead of relying heavily on .skip or .only.
  5. Regularly review skipped tests to avoid forgotten or stale tests.
Self Check Question

Where in this Cypress framework structure would you add describe.only to run only the login tests?

Key Result
Use .skip and .only in Cypress test files to control which tests run during development and debugging.