Cypress 26 ๐ฒ Flaky Test Management โ Retries, testIsolation, and debugging
A flaky test is a test that produces different results on the same code. It is worse than a failing test, because a failing test tells you something is broken while a flaky test tells you nothing โ and it teaches the team to re-run the build until it goes green. The cost is not the wasted CI minutes; it is the gradual loss of trust in the suite, after which a real regression ships because everyone assumed the red was the usual noise.
Cypress ships three levers against flake, and they operate on different timescales. Retries handle it at run time โ the test that failed is re-run automatically, and the report records both the failure and the recovery. testIsolation handles it at test boundaries โ it decides whether cookies, storage, and the page are reset between tests, which is the difference between an isolated test and a test that depends on the one before it. Debugging handles it at authoring time โ Time Travel, .debug(), cy.pause(), and the uncaught:exception handler are what you use to find out why the test is order-dependent or timing-sensitive in the first place.
This chapter covers all three in that order. The retry section walks through the config object, the per-test and per-suite overrides, the this.currentTest introspection that fires inside the retried run, and the important distinction between retrying a flake and fixing one. The isolation section covers what testIsolation: true actually resets, what false actually leaves behind, and why cy.session() is the right answer to the performance problem that makes people reach for false. The debugging section covers Time Travel, .debug(), cy.pause(), the uncaught:exception handler for third-party scripts, cy.task() for Node-side logging, and the artifacts โ video, screenshots, DEBUG output โ that survive a headless CI run.
Key point: Retries hide flake, they do not remove it โ a retried test is still a test that failed in production conditions, and Cypress records the retry count precisely so the suite can be audited later. Use runMode retries to keep the build green while you hunt, keep openMode at zero so local failures stay honest, keep testIsolation: true and solve the slowness with cy.session() rather than by disabling the reset, and treat every test that needed a retry as a bug report against the test itself.
Why flaky test management exists
The re-run reflex. Once a suite has a known flake, the first response to a red build is to re-run it. The reflex is rational โ the odds are that the flake is the flake โ and it is corrosive, because the one time the red is real, the reflex buries it. A retry policy with a recorded count is the disciplined version of the same reflex: the build stays green, but the count appears in the report and the audit is possible.
The four real causes. Almost every flake traces to one of four things: an order dependence between tests, a timing assumption about the network or an animation, a shared resource that another test mutates, or non-deterministic data โ a Date.now(), a random id, a timestamp that crosses a midnight boundary. Retries do not fix any of the four. They only give you more chances for the test to land on the lucky side of the assumption.
The testIsolation trade-off. Before Cypress 12, every test shared the same browser state with the test before it, and resetting it was the author’s job. That made long login flows cheap โ log in once, run ten tests โ and it made order dependence invisible. Cypress 12 made testIsolation: true the default, which clears cookies and storage and navigates to about:blank between every test. The default is correct; the performance problem it creates is real; cy.session() is the answer that keeps both.
The difference between hiding and fixing. A retried test is not a passing test. Cypress reports it as passed in the summary but records attempts and marks the run as flaky in Cypress Cloud. The distinction matters for a release decision: a suite with twelve flaky tests and zero failures has a very different risk profile from a suite with zero of either, and only the second one deserves the green checkmark.
The debugging problem in CI. A flake that reproduces locally is easy โ open the runner, hover the command, look at the DOM. A flake that reproduces only on CI is the common case, and the artifacts have to carry the diagnosis without you: the video of the run, the screenshot at the moment of failure, the command log captured in the run output, and the DEBUG stream from the internals. The tooling only helps if it was turned on before the run that failed.
The trade-off. Retries cost CI time โ every retry is a full re-run of the test plus its hooks. testIsolation: false costs correctness and buys seconds. A verbose DEBUG stream costs output volume and buys the one line you needed. Video costs disk and CPU and buys the failure you cannot reproduce. Every lever in this chapter has a cost, and the discipline is choosing which cost the project can actually afford.
a. Retries โ config, per-test, per-suite
The config object is the normal path, and it has two keys because Cypress has two runners. openMode is cypress open, the interactive runner where you are present and watching. runMode is cypress run, the headless CI run where nobody is watching. The recommended split is runMode: 2 and openMode: 0: keep the build green, keep local failures honest.
// cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
retries: {
runMode: 2, // CI: retry twice, keep the build green
openMode: 0, // local: fail immediately, see the real error
},
},
});
The per-test form is for the individual test known to be timing-sensitive. It accepts a number, which applies to both modes, or an object with the same two keys.
// cypress/e2e/checkout.cy.ts
describe('checkout', () => {
// this one talks to a third-party payment sandbox
it('authorizes a card', { retries: { runMode: 3, openMode: 1 } }, () => {
cy.visit('/checkout');
cy.get('[data-cy=pay]').click();
cy.contains('Authorized').should('be.visible');
});
// this one is deterministic; never retry it
it('validates the form', { retries: 0 }, () => {
cy.visit('/checkout');
cy.get('[data-cy=pay]').click();
cy.contains('Card number is required').should('be.visible');
});
});
The per-suite form applies to every test inside the describe, and the narrower scope wins when both are set. A suite that touches a payment sandbox gets its own policy without polluting the file it lives in.
// the whole suite inherits this retry policy
describe('third-party integrations', { retries: { runMode: 3 } }, () => {
it('loads the Stripe iframe', () => { /* ... */ });
it('redirects to the bank', () => { /* ... */ });
});
The important part is that a retried test runs its hooks again. beforeEach fires on every attempt, which is why a beforeEach that creates a record in a database will create three of them by the time a thrice-retried test passes. Seeding belongs in beforeAll plus an idempotent reset, or in a cy.task() that deletes-then-creates.
// this runs three times if the test retries three times
beforeEach(() => {
cy.task('db:createOrder'); // creates a duplicate on every retry
});
// this runs once, and the test cleans up after itself
before(() => {
cy.task('db:reset');
});
Reading the retry state is what turns a retry into an audit trail. Inside afterEach, this.currentTest is the Mocha test object, and it knows whether the attempt that just finished passed and which attempt it was.
afterEach(function () {
// currentRetry() is 0 on the first attempt, 1 on the first retry
if (this.currentTest.currentRetry() > 0) {
// the test only passed after a retry โ log it as flaky
cy.task('log', `FLAKY: ${this.currentTest.title} ` +
`(attempt ${this.currentTest.currentRetry() + 1})`);
}
if (this.currentTest.state === 'failed') {
cy.screenshot(`failure-${this.currentTest.title}`);
}
});
The cy.task('log', ...) call is the way to get that line into the CI output. A console.log inside afterEach runs in the browser, where nobody is reading; a cy.task runs in Node, where the CI log is.
The final piece is the .skip and .only pair, which are debugging tools that occasionally become flake tools. A flaky test that needs investigation should be .skipped with a linked issue rather than deleted, and .only should never reach CI โ the forbidOnly equivalent in Cypress is a lint rule or a CI grep for .only in the spec files.
// skipped with a reason, not deleted
it.skip('uploads a 50MB file', () => { /* https://jira/BUG-1234 */ });
// `.only` runs nothing else; never commit it
it.only('the one I am debugging', () => { /* ... */ });
b. testIsolation โ what is reset and what is not
testIsolation is a Cypress 12+ option, default true, and it governs what happens between every it. With it on, Cypress clears cookies, localStorage, and sessionStorage, and navigates the page to about:blank before the next test starts. Every test therefore begins from the same state, and order dependence becomes impossible โ a test that relied on the previous test’s login fails immediately instead of failing in CI two weeks later.
// cypress.config.ts (default; shown for clarity)
export default defineConfig({
e2e: {
testIsolation: true, // reset cookies + storage + page per test
},
});
Turning it off is a decision about what the test inherits, and it is worth being explicit about what false actually leaves in place. Cookies persist, localStorage and sessionStorage persist, the page is not reset, and the previous test’s cy.visit() is still the current document. That is why a test with testIsolation: false can skip its own cy.visit() โ and why it silently depends on the test above it having done one.
// only this test opts out of the reset
it('continues from the previous state', { testIsolation: false }, () => {
// no cy.visit(); the page from the last test is still loaded
cy.get('[data-cy=next]').click(); // reads cookies set by the test above
});
The performance motive is real, and it is almost always the wrong fix. A login flow that takes four seconds, repeated across forty tests, is 160 seconds of the run spent typing the same credentials. Disabling isolation removes that cost and replaces it with hidden coupling. The correct fix is cy.session(), which caches the result of the login โ the cookies and storage it produced โ and restores it in a fraction of a second while still running inside a fully isolated test.
// cypress/support/commands.ts
Cypress.Commands.add('login', (email: string, password: string) => {
// the session key identifies the cached state; setup runs only on a miss
cy.session([email, password], () => {
cy.visit('/login');
cy.get('[data-cy=email]').type(email);
cy.get('[data-cy=password]').type(password);
cy.get('[data-cy=signin]').click();
cy.url().should('include', '/dashboard');
});
});
// every test calls cy.login(), only the first one pays for it
beforeEach(() => {
cy.login('user@example.com', 'secret'); // ~40ms after the first run
cy.visit('/orders');
});
cy.session() also has an options bag for the validate callback, which is the check that decides whether the cached state is still good. Without it, an expired token in a long session is restored and every test fails with a redirect to the login page.
cy.session([email], () => { /* setup */ }, {
// runs on every restore; return falsy to force a fresh setup
validate() {
cy.request('/api/me').its('status').should('eq', 200);
},
cacheAcrossSpecs: true, // reuse the session across spec files
});
cacheAcrossSpecs: true is the setting that makes the saving show up across an entire run rather than within one file. It is the closest Cypress has to Playwright’s storageState, and it is the answer to the “login is slow” complaint that leads people to testIsolation: false.
The rule of thumb is therefore: keep testIsolation: true, reach for cy.session() when the setup is expensive, and only use testIsolation: false for a genuine multi-step flow that cannot be expressed as one test โ a wizard with a server-side step in the middle, or an OAuth callback that only works once per session.
c. Debugging โ Time Travel, .debug(), cy.pause(), and the exception handler
Time Travel is the interactive runner’s core feature and the one thing the headless run cannot reproduce. Every command in the Command Log has a snapshot of the DOM taken before it and after it. Hovering a command pins the application to that moment; clicking it pins the snapshot so you can inspect the DOM in DevTools while the state is frozen.
// hover "type" in the Command Log to see the input filled
// click it to pin the snapshot, then inspect in devtools
cy.get('[data-cy=email]').type('user@example.com');
The snapshot shows the DOM as it was, but not the JavaScript state โ no component internals, no Redux store, no window variables. Time Travel answers “what did the page look like”, not “what was in memory”.
.debug() is the command that bridges the two. On a query, it drops a debugger statement into the chain, so the browser pauses at that exact command with the subject in scope. In run mode there is no DevTools attached and the same call pauses the runner instead, which is why .debug() behaves like cy.pause() in CI.
cy.get('[data-cy=email]')
.debug() // pause here, subject in scope
.type('user@example.com');
cy.pause() pauses the whole run at that point and puts the runner into step mode, where the play button advances one command at a time. It is the closest thing to a breakpoint that survives the queue model โ the state is live, the app is running, and the next command has not fired yet.
cy.visit('/checkout');
cy.pause(); // step through from here
cy.get('[data-cy=pay]').click();
For anything inside a .then() callback โ reading a value, computing a selector โ the plain JavaScript debugger statement works, because the callback is ordinary code running in the browser.
cy.get('[data-cy=total]').then(($el) => {
const text = $el.text();
debugger; // DevTools pauses here with `text` in scope
expect(parseFloat(text)).to.be.greaterThan(0);
});
The uncaught:exception handler is the escape hatch for errors that come from somewhere other than the application. A third-party analytics script that throws on an ad blocker, a browser extension injecting into the page, a React hydration warning from a library โ all of these fail the test by default, because Cypress fails a test on any uncaught exception. Returning false from the handler stops the failure for that one error.
// cypress/support/e2e.ts
Cypress.on('uncaught:exception', (err, runnable) => {
// ignore a known, third-party, non-fatal error
if (err.message.includes('ResizeObserver loop limit exceeded')) {
return false; // do not fail the test
}
// everything else still fails, which is what you want
return true;
});
The handler must be narrow. A blanket return false hides the real uncaught exception that was causing the flake, and the test then fails later, in a place that has nothing to do with the cause.
cy.task() is the Node-side logging channel. The test body runs in the browser, so a console.log there lands in the browser console, which the CI run does not capture usefully. A task runs in Node, and its output goes to the CI log.
// cypress.config.ts
import { defineConfig } from 'cypress';
import fs from 'node:fs';
export default defineConfig({
e2e: { baseUrl: 'http://localhost:3000' },
setupNodeEvents(on) {
on('task', {
log(message: string) {
fs.appendFileSync('cypress.log', message + '\n');
console.log('[task]', message); // appears in the CI output
return null; // tasks must return or throw
},
});
},
});
The internals DEBUG stream is the last resort and the one that answers “why did Cypress do that”. DEBUG=cypress:* turns on the runner’s own logging, and the namespaces are granular enough to narrow to one subsystem.
# everything โ very loud
DEBUG=cypress:* npx cypress run
# the network proxy only, which is where an intercept bug shows up
DEBUG=cypress:net-stubbing* npx cypress run
# the spec loader, for a bundling error
DEBUG=cypress:webpack* npx cypress run
The artifacts are what remains when the run is over. Video is on by default in cypress run; screenshots on failure are on by default and land in cypress/screenshots. Both are configurable, and both are the only evidence of a failure that did not reproduce.
// cypress.config.ts (excerpt)
export default defineConfig({
e2e: {
video: true, // record every run-mode test
videosFolder: 'cypress/videos',
screenshotOnRunFailure: true, // one PNG per failure
screenshotsFolder: 'cypress/screenshots',
numTestsKeptInMemory: 0, // stop retaining DOM in run mode
},
});
numTestsKeptInMemory is worth knowing because it is the cause of the “Cypress became slow and then crashed” report. In cypress open, the runner retains the snapshots for the last fifty tests so Time Travel works; on a long spec, that is fifty copies of the DOM in memory. Dropping it to 0 in run mode removes the retention, and Time Travel is the feature that gets traded for the stability.
Getting the failure details right requires recording the failure in afterEach, where the test object and the DOM are both still live:
afterEach(function () {
if (this.currentTest.state === 'failed') {
// attach the console and the URL to the run output
cy.url().then((url) => cy.task('log', `FAILED at ${url}`));
cy.screenshot(`${this.currentTest.title}`, { capture: 'viewport' });
}
});
{ capture: 'viewport' } is the setting that makes the screenshot show what the user saw rather than the full scrollable page. For a failure in a modal, the full-page capture shows the entire page and the modal is the interesting part.
Complete Example Session
// ============================================
// PART 1: THE CONFIG AND THE RETRY POLICY
// ============================================
// cypress.config.ts
import { defineConfig } from 'cypress';
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
retries: { runMode: 2, openMode: 0 },
video: true,
screenshotOnRunFailure: true,
numTestsKeptInMemory: 0,
},
setupNodeEvents(on) {
on('task', {
log(message: string) {
console.log('[task]', message); // visible in CI
return null;
},
});
},
});
// ============================================
// PART 2: THE PER-TEST OVERRIDE
// ============================================
// cypress/e2e/payments.cy.ts
describe('payments', () => {
it('authorizes a card', { retries: { runMode: 3 } }, () => {
cy.visit('/checkout');
cy.get('[data-cy=pay]').click();
cy.contains('Authorized').should('be.visible');
});
it('rejects an expired card', { retries: 0 }, () => {
cy.visit('/checkout');
cy.get('[data-cy=pay]').click();
cy.contains('Card expired').should('be.visible');
});
});
// ============================================
// PART 3: THE FLAKE AUDIT
// ============================================
// cypress/support/e2e.ts
afterEach(function () {
const attempt = this.currentTest.currentRetry() + 1;
// a passing test with attempt > 1 was retried; that is a flake
if (this.currentTest.state === 'passed' && attempt > 1) {
cy.task('log', `FLAKY ${this.currentTest.title} attempt ${attempt}`);
}
// a still-failing test gets a screenshot and its URL logged
if (this.currentTest.state === 'failed') {
cy.url().then((url) => cy.task('log', `FAILED at ${url}`));
cy.screenshot(`failure-${this.currentTest.title}`, {
capture: 'viewport',
});
}
});
// ============================================
// PART 4: THE SESSION CACHE
// ============================================
Cypress.Commands.add('login', (email: string, password: string) => {
cy.session([email, password], () => {
cy.visit('/login');
cy.get('[data-cy=email]').type(email);
cy.get('[data-cy=password]').type(password);
cy.get('[data-cy=signin]').click();
cy.url().should('include', '/dashboard');
}, {
cacheAcrossSpecs: true, // shared across spec files
validate() {
cy.request({ url: '/api/me', failOnStatusCode: false })
.its('status')
.should('eq', 200); // force a re-login on 401
},
});
});
// ============================================
// PART 5: THE ISOLATED TEST
// ============================================
beforeEach(() => {
cy.login('user@example.com', 'secret'); // ~40ms after the first call
});
it('lists orders', () => {
cy.visit('/orders');
cy.get('[data-cy=order-row]').should('have.length.greaterThan', 0);
});
// ============================================
// PART 6: THE OPT-OUT, DELIBERATELY
// ============================================
it('step one of the wizard', { testIsolation: false }, () => {
cy.visit('/wizard');
cy.get('[data-cy=step-one]').click();
});
it('step two of the wizard', { testIsolation: false }, () => {
// no cy.visit(); the server-side wizard state is in the cookie
cy.get('[data-cy=step-two]').click();
});
// ============================================
// PART 7: THE EXCEPTION FILTER
// ============================================
Cypress.on('uncaught:exception', (err) => {
// a known third-party error, narrow and documented
if (err.message.includes('ResizeObserver loop')) return false;
return true; // everything else still fails
});
// ============================================
// PART 8: THE DEBUG BREAKPOINT
// ============================================
it('inspects the computed total', () => {
cy.visit('/cart');
cy.get('[data-cy=total]')
.debug() // pause, subject in scope
.then(($el) => {
const text = $el.text();
debugger; // DevTools breakpoint
expect(parseFloat(text)).to.be.greaterThan(0);
});
});
// ============================================
// PART 9: THE NETWORK DELAY
// ============================================
cy.intercept('GET', '/api/orders', (req) => {
req.on('response', (res) => { res.setDelay(2000); }); // simulate slow
});
it('shows a spinner then the rows', () => {
cy.visit('/orders');
cy.get('[data-cy=spinner]').should('be.visible');
cy.get('[data-cy=order-row]').should('have.length.greaterThan', 0);
});
// ============================================
// PART 10: THE CI RUN WITH DEBUG
// ============================================
// $ DEBUG=cypress:net-stubbing* npx cypress run \
// --browser chrome --reporter junit
//
// $ npx cypress run --spec "cypress/e2e/payments.cy.ts"
The ten parts covered the config and retry policy, the per-test override, the flake audit in afterEach, the cy.session() cache with a validate callback, the isolated test, the deliberate testIsolation: false opt-out, the narrow uncaught:exception filter, the .debug() breakpoint, the cy.intercept delay, and the CI run with the internals DEBUG stream.
Quick Reference
Retry configuration
| Scope | Syntax |
|---|---|
| Global | retries: { runMode: 2, openMode: 0 } |
| One test | it('name', { retries: 2 }, fn) |
| One suite | describe('name', { retries: { runMode: 3 } }, fn) |
| Both modes | { retries: 2 } (number) |
| None | { retries: 0 } |
Retry introspection
| Property | Returns |
|---|---|
this.currentTest.title | Test name |
this.currentTest.state | 'passed' / 'failed' / 'pending' |
this.currentTest.currentRetry() | 0 on first attempt, 1 on first retry |
this.currentTest.retries() | Configured max retries |
Isolation
| Setting | Resets |
|---|---|
testIsolation: true | Cookies, storage, page โ about:blank |
testIsolation: false | Nothing; the next test inherits the last page |
cy.session() | Caches cookies + storage per session key |
cacheAcrossSpecs: true | Reuses the session across spec files |
Debugging primitives
| Tool | Mode | Effect |
|---|---|---|
| Time Travel hover | open | Pins the DOM snapshot to that command |
.debug() | open | Drops a debugger with the subject in scope |
.debug() | run | Acts as cy.pause() |
cy.pause() | open | Step mode from that point |
debugger in .then() | open | DevTools breakpoint with locals |
cy.task('log', ...) | both | Node-side log, visible in CI |
DEBUG=cypress:* | run | Internal Cypress logs |
uncaught:exception | both | Filter third-party errors |
Artifacts
| Artifact | Default | Location |
|---|---|---|
| Video | On in run mode | cypress/videos |
| Screenshot on failure | On | cypress/screenshots |
| Command log | Captured in stdout | โ |
| Trace | Not available | Use Time Travel in open mode |
Best Practices
โ Do This:
// Retry in CI, fail fast locally
retries: { runMode: 2, openMode: 0 } // โ
// Log every retried test as a flake
if (this.currentTest.currentRetry() > 0) cy.task('log', 'FLAKY'); // โ
// Cache the login instead of disabling isolation
cy.session([email], () => { /* ... */ }, { cacheAcrossSpecs: true }); // โ
// Keep isolation on by default
testIsolation: true // โ
// Narrow the exception filter to a documented error
if (err.message.includes('ResizeObserver loop')) return false; // โ
// Screenshot the viewport on failure
cy.screenshot(title, { capture: 'viewport' }); // โ
// Use cy.task for anything that must reach CI
cy.task('log', `FAILED at ${url}`); // โ
โ Don’t Do This:
// Retry locally to make a red test green
retries: { openMode: 3 } // โ
// Assume a retried test passed first time
// (it did not; that is the point of the count) // โ
// Disable isolation to speed up logins
testIsolation: false // โ
// Swallow every uncaught exception
Cypress.on('uncaught:exception', () => false); // โ
// Console.log in the test body expecting CI to see it
console.log('debug'); // โ
// Leave it.only in the suite
it.only('debugging', () => { /* ... */ }); // โ
// Fix flake with cy.wait(500)
cy.wait(500); // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Retry hides a real bug | Retry count not audited | Log currentRetry() in afterEach |
| Duplicate database rows | beforeEach runs per attempt | Seed idempotently or in beforeAll |
| Test passes alone, fails in suite | Shared state | Keep testIsolation: true |
| Login is slow | Repeated full flow | cy.session() with cacheAcrossSpecs |
| Session restored but expired | No validate | Add a cy.request status check |
| Flake still unexplained | Tests fail silently | DEBUG=cypress:net-stubbing* |
uncaught:exception hides everything | Blanket return false | Narrow to a message match |
| Screenshot shows the wrong element | Full-page capture | { capture: 'viewport' } |
| Runner slows then crashes | Snapshots retained | numTestsKeptInMemory: 0 |
Real-World Examples
1. Global retry policy
retries: { runMode: 2, openMode: 0 }
2. Per-test override
it('authorizes', { retries: { runMode: 3 } }, () => { /* ... */ });
3. Flake audit
if (this.currentTest.currentRetry() > 0) cy.task('log', 'FLAKY');
4. Failure screenshot
cy.screenshot(title, { capture: 'viewport' });
5. Session cache
cy.session([email, password], () => { /* login flow */ });
6. Session validation
validate() { cy.request('/api/me').its('status').should('eq', 200); }
7. Isolation opt-out
it('step two', { testIsolation: false }, () => { /* ... */ });
8. Narrow exception filter
if (err.message.includes('ResizeObserver loop')) return false;
9. Debug pause
cy.get('[data-cy=total]').debug().then(($el) => { /* ... */ });
10. Internals debug
DEBUG=cypress:net-stubbing* npx cypress run
Visual
The retry lifecycle
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE RETRY LIFECYCLE โ
โ โ
โ attempt 0 โโโบ beforeEach โโโบ test โโโบ โ failed โ
โ โ
โ attempt 1 โโโบ beforeEach โโโบ test โโโบ โ passed โ
โ โ
โ reported as "passed" but currentRetry() is 1 โ
โ โ
โ openMode: 0 runMode: 2 โ
โ fail fast locally keep the build green in CI โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Isolation and sessions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ISOLATION vs SESSIONS โ
โ โ
โ testIsolation: false โ
โ test A: login โโโโโโโโโโโโโโโโโโโโโโบ orders โ
โ test B: (inherits page + cookies) โโโบ cart โ
โ hidden coupling; cheap, fragile โ
โ โ
โ testIsolation: true + cy.session() โ
โ test A: restore session โโโบ orders โ
โ test B: restore session โโโบ cart โ
โ ~40ms each; independent, stable โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Debugging layers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DEBUGGING LAYERS โ
โ โ
โ cypress open hover โ DOM snapshot (Time Travel) โ
โ .debug() โ breakpoint (subject scope) โ
โ cy.pause() โ step mode โ
โ โ
โ cypress run cy.task('log') โ CI stdout โ
โ video โ cypress/videos โ
โ screenshot โ cypress/screenshots โ
โ DEBUG=cypress:* โ internals โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The flake triage decision
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FLAKE TRIAGE โ
โ โ
โ failed once in CI โ
โ โ โ
โ โโโโบ reruns, passes โ
โ โ โโโโบ log as FLAKY, open a ticket โ
โ โ โ
โ โโโโบ fails every time โ
โ โโโโบ real failure, not flake โ
โ โ
โ flaky > 2% of runs? โ
โ โโโโบ do not raise retries; fix the test โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| Global retries | retries: { runMode, openMode } |
| Recommended split | runMode: 2, openMode: 0 |
| Per-test | it(name, { retries }, fn) |
| Retry count | this.currentTest.currentRetry() |
| Isolation default | testIsolation: true (v12+) |
| Reset behaviour | Cookies, storage, page โ about:blank |
| Session cache | cy.session() with optional validate |
| Cross-spec cache | cacheAcrossSpecs: true |
| Exception filter | Cypress.on('uncaught:exception', ...) |
| Node-side log | cy.task('log', message) |
| Internals log | DEBUG=cypress:* |
| Memory retention | numTestsKeptInMemory: 0 in run mode |
Key takeaways:
- Retries hide flake, they do not fix it. A test reported as passed after a retry is still a test that failed under production conditions.
this.currentTest.currentRetry()insideafterEachis the line that puts the count into the CI log, and a suite that never reads it is a suite that is accumulating unknown risk. - Split the policy:
runMode: 2,openMode: 0. Retries exist to keep a build green when a third-party sandbox hiccups. When you are watching the runner, a failure should be immediate and honest, because that is the moment you can actually diagnose it. beforeEachruns on every attempt. A hook that writes to a database writes once per retry. The retry count and the seed must be designed together, or the fix for the flake becomes a new source of duplicates.testIsolation: trueis the correct default andcy.session()is the correct escape. Clearing cookies and storage between every test removes order dependence entirely. The performance motive for turning it off is real, and caching the login withcy.session()pluscacheAcrossSpecs: trueand avalidatecallback solves it without giving up the isolation.- A narrow
uncaught:exceptionfilter is a tool; a blanketreturn falseis a cover-up. The handler exists for the ResizeObserver loop, the extension that injects into the page, and the analytics script that throws on an ad blocker. Everything else should still fail, because it is probably the reason the test was flaky. - Time Travel is the best debugging feature in the tool and it only works in
cypress open. The headless run gives you video, screenshots, and the CI log. That is why the failure path belongs inafterEachโ the URL and the viewport screenshot have to be captured while the DOM is still alive. - Every lever has a cost. Retries cost CI minutes, verbose
DEBUGcosts log volume, video costs CPU and disk,numTestsKeptInMemory: 50costs memory on a long spec. Choosing which cost a project can bear is the actual management work; there is no configuration in which all of them are free.
Remember: Flake management is three separate jobs wearing the same hat. Retries are a containment measure โ they keep the build usable while the work continues, and the count in afterEach is what stops containment from becoming concealment. Isolation is a correctness measure โ testIsolation: true is the default worth keeping, and cy.session() is the performance answer that does not require trading it away. Debugging is the diagnosis measure โ Time Travel and .debug() locally, cy.task('log'), video, and screenshots in CI. A suite that uses only the first is green and untrustworthy; a suite that uses all three is the one where a red run actually means something.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!