Configuration Strategy
This framework uses separate configuration files for UI and API tests, allowing each test type to have optimized settings:cypress.config.ui.ts
Configuration for UI tests targeting web applications
cypress.config.api.ts
Configuration for API tests targeting REST endpoints
UI Test Configuration
The UI configuration is optimized for browser-based testing:cypress.config.ui.ts
UI Configuration Options
baseUrl
baseUrl
The base URL for all Usage in tests:
cy.visit() commands in UI tests.specPattern
specPattern
Glob pattern to locate UI test files.This pattern:
- Looks in
cypress/e2e/ui/directory - Matches all files ending in
.cy.ts - Includes files in subdirectories (
**)
cypress/e2e/ui/LoginPageSpec.cy.tscypress/e2e/ui/checkout/payment.cy.ts
watchForFileChanges
watchForFileChanges
Controls whether Cypress auto-reloads tests when files change.
false: Tests don’t auto-reload (recommended for stability)true: Tests reload on file changes (can be distracting)
Setting this to
false prevents unexpected test reruns during development, giving you more control.supportFile
supportFile
Path to the file that loads before all tests.This file typically imports:
- Custom commands
- Global hooks
- Third-party plugins
API Test Configuration
The API configuration targets REST endpoints:cypress.config.api.ts
API Configuration Differences
Running with Different Configurations
Use the--config-file flag to specify which configuration to use:
Additional Configuration Options
You can extend configurations with additional Cypress options:Viewport Settings (UI Tests)
cypress.config.ui.ts
Timeout Settings
Video and Screenshot Settings
Browser Launch Options
Environment Variables
Use environment variables for dynamic configuration:Configuration Inheritance
You can create a base configuration and extend it:cypress.config.base.ts
cypress.config.ui.ts
setupNodeEvents
ThesetupNodeEvents function allows you to tap into Node.js events:
- Database seeding
- File system operations
- Custom reporting
- Environment-specific setup
Configuration Best Practices
Separate Concerns
Keep UI and API configurations separate for clarity and optimization
Use Environment Variables
Never hardcode sensitive data or environment-specific values
Document Custom Settings
Add comments explaining non-obvious configuration choices
Share Common Settings
Use configuration inheritance for shared options
Troubleshooting
Tests not running
Tests not running
Check that
specPattern matches your test file locations:Wrong baseUrl used
Wrong baseUrl used
Ensure you’re using the correct config file:
Support file not loading
Support file not loading
Verify the
supportFile path is correct:Next Steps
Writing UI Tests
Apply UI configuration in your tests
Writing API Tests
Use API configuration for endpoint testing
Running Tests
Execute tests with different configurations
Maintainability
Keep configurations clean and maintainable