How does cypress open differ from cypress run?
cypress open opens an interactive Test Runner for writing and debugging, while cypress run executes tests without a UI for CI. The modes differ in browser, window size, machine resources and retries: retries.runMode and retries.openMode. Run prints results to the console and takes a screenshot on failure. When a test is green locally and red in CI, reproduce the CI mode with cypress run in the same browser.
Cypress · Architecture
A test is green in cypress open but fails in CI. What changed between the two runs?
A developer writes a test in the interactive window, sees green steps and pushes. In CI the same test goes red. Often the cause is not the test code but the run mode: open and run differ in browser, retries, UI and what is available after a failure. This lesson explains what each mode is for and what to check when the results diverge.
How it works and why. cypress open opens the interactive Test Runner: you pick a spec, see every command in the Command Log, can go back to any step (time travel) and the test reruns when you save the file. This is the mode for writing and debugging. cypress run runs tests with no UI, prints the result to the console and takes a screenshot on failure. This is the mode for CI. The difference is deliberate: a person needs feedback, a machine needs a fast and repeatable run.
Two run modes
For writing and debugging
Interactive Test Runner, time travel through steps, a rerun after you save a file. Retries are 0 by default.
For CI and batch runs
No UI, console output, screenshots on failure. retries.runMode applies here if set.
In run with no flags tests run headless in Electron, but since Cypress 16 Electron is deprecated as a test browser and will be removed in a future major version. So in CI it is better to name the browser explicitly: --browser chrome or defaultBrowser in the config. Retries are set separately per mode: retries.runMode and retries.openMode. Video is turned on with the video option, and run takes screenshots on failure.
Example: a gap between open and run. The main commands:
npx cypress open # interactive
npx cypress run # headless, all specs
npx cypress run --browser chrome # a specific browser
npx cypress run --spec "cypress/e2e/login.cy.ts"
npx cypress run --headed # with the browser window
The test passes in open, in Chrome, on a laptop with a wide screen and a fast network, while CI runs it in a different browser with a different window size on a slower machine. Diagnosis starts with equalising conditions, not with editing the test:
- run the same
cypress run --browser <the CI browser>locally to reproduce the CI mode; - check the viewport and window size in the config, because responsive layout changes elements;
- look at the screenshot and the failure log that
runproduces; - remember retries: in
runthe test may have failed several times and passed, so it is flaky, not green.
A config that tells the modes apart:
export default defineConfig({
e2e: {
// no retries in open, up to two in run
retries: { runMode: 2, openMode: 0 },
},
});
Different values for open and run make sense: in development retries mask a problem, in CI they reduce noise. But a test that passes only on a retry must be fixed, not ignored.
The analogue is npx playwright test, headless by default. Instead of a Test Runner there is --ui (UI mode with a timeline and DOM snapshots), --debug with the inspector and --headed. Browsers are chosen with --project, not --browser.
Limits and alternatives. Interactive mode does not replace CI: it does not guarantee the same conditions (browser, window size, machine resources). run gives screenshots and a log but no interactive debugging: for that, reproduce the failure in open with the same data. For quick review in CI, video and artifacts are useful, stored as build artifacts.
Common mistakes.
- Checking a test only in
openand not runningrunlocally before a push. - Relying on the default browser in CI: after version changes it may become a different one.
- Treating a test as green when it passed in
runonly with a retry. - Setting the same retries for open and run: in development they hide flakiness.
Check yourself
A test passes in cypress open but fails in CI on a button click. Which three differences between the runs do you check first?
Answer
The browser (CI may use another), the window size/viewport (responsive layout can hide the button) and the speed and resources of the machine (slower loading). Then the failure screenshot from run, and a local reproduction through cypress run with the same browser.
In CI a test is marked passed, but the log shows it failed twice. What does that mean?
Answer
retries.runMode kicked in: the test was rerun and passed. It is formally green but unstable, because the result depends on a retry. It must be investigated as flaky, not trusted as reliable.