Timeouts control how long Cypress waits for actions or elements before failing.
- Global Timeout: Set in
cypress.config.js under defaultCommandTimeout and pageLoadTimeout.
- Test or Command Level Timeout: Override global timeout by passing
{ timeout: ms } option to commands like cy.get() or cy.visit().
- Retries: Configure retries on test failure with
retries option in config.
- Environment Variables: Use
env in config or CYPRESS_ prefixed system variables to customize timeouts per environment.
Example cypress.config.js snippet:
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
baseUrl: 'https://example.com',
defaultCommandTimeout: 8000, // Wait 8 seconds for commands
pageLoadTimeout: 60000, // Wait 60 seconds for page load
retries: 2, // Retry failed tests twice
env: {
loginTimeout: 10000 // Custom env variable for login timeout
}
}
})