Prompt
why do my Cypress tests fail in CI but pass locally
Latest observation
Oct 10, 2026
OpenAI APIWeb search: off
Cypress tests often pass locally and fail in CI because CI is usually a different environment in ways that expose timing, dependency, and configuration issues.
Common causes:
1) Timing / flakiness
- CI machines are often slower.
- Tests that rely on fixed waits (
cy.wait(1000)) or assume elements appear instantly can fail. - Animations, network requests, or rendering may take longer in CI.
Fix:
- Prefer retries/assertions like
cy.get(...).should(...) - Avoid arbitrary waits
- Wait on network aliases when possible
2) Different viewport / headless browser behavior
- CI usually runs Cypress in headless mode
- Default browser size may differ from local
- Responsive layouts may change selectors or element visibility
Fix:
- Set viewport explicitly in tests or config
- Check for hidden/overlapping elements
3) Missing or different environment variables
- Local
.envvalues may not exist in CI - API URLs, auth tokens, feature flags, etc. may be missing or wrong
Fix:
- Verify CI env vars are set
- Print safe diagnostic info in CI
- Use config files consistently
4) Test data/state differences
- Local environment may already have seeded data
- CI often starts from a clean slate
- Tests may depend on order or leftover state
Fix:
- Seed data before tests
- Make tests independent
- Reset state between tests
5) External services are unstable or unavailable
- Third-party APIs, auth providers, emails, payment services may behave differently in CI
- Network latency or rate limits can cause failures
Fix:
- Stub/mocking for external calls
- Use test doubles or dedicated test environments
6) Parallelization/order dependence
- CI may run specs in a different order, or in parallel
- Tests that share data or assume previous tests ran will fail
Fix:
- Make each test self-contained
- Avoid global shared state
7) Browser/Cypress version mismatch
- Local and CI may use different Node, Cypress, or browser versions
Fix:
- Pin versions in lockfiles and CI images
- Use the same Docker image or Cypress base image if possible
8) File system / path / permissions differences
- CI paths are often case-sensitive
- Local OS may be macOS/Windows, CI usually Linux
- File uploads/downloads or fixture paths may break
Fix:
- Check path casing
- Avoid OS-specific assumptions
9) Authentication/session issues
- Cookies, localStorage, or session caching may behave differently in headless CI
- SSO or redirect flows may time out
Fix:
- Use
cy.session()carefully - Ensure auth is reliable and repeatable
10) Test assertions are too strict
- Asserting exact text, order, or timing can fail if CI changes rendering slightly
Fix:
- Make assertions more resilient
- Assert meaningful behavior, not implementation details
How to debug quickly
-
Run Cypress in CI-like mode locally
- headless
- same browser
- same env vars
- same viewport
-
Look at screenshots/videos
- Cypress can capture them on failure
-
Add logging around the failing step
- network responses
- current URL
- DOM state
-
Check command retries
- If the app is slow, increase timeouts carefully
-
Compare local vs CI versions
- Node
- Cypress
- browser
- OS/container image
Most likely culprit
If tests are “fine locally but flaky in CI,” the most common reason is:
the test is too dependent on timing or shared state.
If you want, I can help you debug a specific failure if you paste:
- the failing test
- the CI error message
- your Cypress config
- your CI environment details
Brands