Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteUse cy.session() when a test needs a login or other server-created browser state; use cy.setCookie() in beforeEach when the cookie value is already known. Cypress test isolation clears cookies before each test by default, so a cookie created in one test is not a dependable way to prepare the next. Keep isolation enabled for independent tests; disable it only for a deliberately stateful block.
Why Cypress does not keep a cookie from one test to the next
With test isolation enabled, Cypress clears cookies, localStorage, and sessionStorage before each test. That behavior prevents one test’s browser state from silently affecting another. It also explains why logging in once in one test and expecting the next test to remain logged in usually fails. See the Cypress test isolation documentation.
Preserving cookies should generally mean recreating or restoring the required state for each test, not relying on test order. Choose the pattern based on where the cookie comes from:
- Authentication or server-created state: use
cy.session(). - A fixed value known to the test: set it with
cy.setCookie()inbeforeEach. - A genuinely stateful sequence of tests: set
testIsolation: falsenarrowly, accepting the coupling risk. - Reuse across spec files in one run: use
cy.session()withcacheAcrossSpecs: true.
Use cy.session() for login and server-created cookies
cy.session() caches and restores cookies, local storage, and session storage for a session ID. It is usually the best fit when logging in creates an authentication cookie or when multiple tests need the same authenticated state. Cypress documents the command and its options at cy.session().
#1 Best Overall
Example: establish and validate a user session
const login = (name = 'user1') => {
cy.session(
name,
() => {
cy.request({
method: 'POST',
url: '/login',
body: { name, password: 's3cr3t' },
})
},
{
validate() {
cy.visit('/user_profile')
cy.contains(`Hello ${name}`)
},
cacheAcrossSpecs: true,
},
)
}
describe('profile', () => {
beforeEach(() => {
login()
cy.visit('/user_profile')
})
it('shows the signed-in user', () => {
cy.contains('Hello user1')
})
})
The setup callback performs the login request. Cypress saves the browser storage state created during setup; validation checks that a restored session is still usable. The example’s validation visits the profile and looks for the expected greeting. Adapt the endpoint, request body, and assertion to the application’s actual login flow.
With test isolation enabled, Cypress clears the page and browser context while establishing or restoring a session. Call cy.visit() after cy.session() before interacting with the page under test. In the example, validation visits the profile to confirm authentication, and the test setup visits it again to start the test on that page.
Make the session ID reflect the identity and login conditions
The first argument is the session ID. Use a stable ID that identifies the user and any setup conditions that change the resulting state. For example, if a session can represent different roles or tenants, include those distinctions in the ID rather than reusing one ID for materially different sessions. A session ID that is too broad risks restoring the wrong identity; one that changes unnecessarily prevents useful reuse.
When validation fails
If validation fails, Cypress treats the cached state as invalid and runs setup again. A validation check should establish that the session is usable, not merely that a cookie exists: the server may have expired, revoked, or rejected an otherwise present cookie. Choose an assertion tied to an authenticated page or a suitable authenticated request.
Set a known cookie before every test
For consent preferences, a known feature flag, or another fixed cookie that does not require a login flow, set it explicitly in beforeEach. The hook runs for each test, so isolation can remain enabled.
Rank #2
beforeEach(() => {
cy.setCookie('cookieConsent', 'accepted')
cy.visit('/dashboard')
})
This approach is appropriate when the test controls the value and the application accepts that cookie without a preceding server-side authentication exchange. It is not a substitute for a real login when the application requires server-created state, a signed token, or related storage.
Cookies shared across subdomains
Cypress cookie commands use the hostname as the default cookie domain. If your application genuinely needs a cookie shared across subdomains, pass an explicit domain option to cy.setCookie(), using the domain expected by the application and test environment. For example:
cy.setCookie('cookieConsent', 'accepted', {
domain: 'example.com',
})
Do not set a broader domain simply to make a test pass: the cookie’s domain must match the behavior being tested. Cypress covers cookie behavior and the migration from older preservation APIs in its migration guide.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
When to disable test isolation
Set testIsolation: false only when the tests intentionally form a stateful sequence and sharing the page or browser state is part of the test design. For example:
describe('Marketing pages', { testIsolation: false }, () => {
before(() => {
cy.setCookie('cookieConsent', 'accepted')
cy.visit('/home')
})
it('shows the home page', () => {
cy.contains('Home')
})
it('can visit the about page', () => {
cy.visit('/about')
cy.contains('About')
})
})
With isolation disabled for this block, browser state and the page are kept available across its tests. The trade-off is that later tests can depend on earlier ones or leave state that changes the result of another test. Run each test individually as well as in sequence to expose order dependence. Prefer a session or explicit per-test cookie setup if tests are meant to stand alone.
Rank #3
Reuse a session across spec files
Set cacheAcrossSpecs: true in the cy.session() options when multiple spec files should be able to restore the same session during one cypress run on one machine. The cache is held in memory, is empty at the start of a new run, and is not shared between parallel CI machines. It is not a persistent login store.
For cross-spec reuse, keep the session definition consistent wherever it is used: the session ID, setup, validation, and option values must match. If separate specs define the same ID with different login behavior or validation, they are not defining the same reusable session. See Cypress’s session documentation for the cache scope and requirements.
Free tools Windows power users keep installed
One-click scans. No signup required.
What cross-spec caching does not do
- It does not preserve a session into the next Cypress run.
- It does not distribute session state to separate parallel CI machines.
- It does not remove the need for validation or a suitable recovery path if authentication expires.
Choose the right pattern
| Pattern | Use it when | Isolation | Main caution |
|---|---|---|---|
cy.session() |
Login or other server-created state must be reused. | Can remain enabled. | Use a meaningful ID and validate that the restored state still works. |
cy.setCookie() in beforeEach |
The test knows the cookie value in advance. | Can remain enabled. | A fixed cookie is not equivalent to a server-authenticated session. |
testIsolation: false |
A block is intentionally a stateful sequence. | Disabled for that block. | State leakage can make tests order-dependent. |
cacheAcrossSpecs: true |
Specs need the same session in one run on one machine. | Used with cy.session(); isolation can remain enabled. |
Not shared across runs or parallel machines; definitions must match. |
Replace removed cookie-preservation APIs
Older examples may use Cypress.Cookies.defaults or Cypress.Cookies.preserveOnce. These APIs were removed. Replace them with cy.session() for reusable authentication state or explicit cy.setCookie() setup for a known value. The removal is documented in the Cypress migration guide.
Troubleshoot cookies that disappear or sessions that fail
The next test is logged out
Cause: Test isolation cleared browser storage before the test, or the session was never restored. Fix: Put the login flow in cy.session() and call it from the test setup, or recreate a known cookie in beforeEach.
A cookie exists but the application still rejects the user
Cause: The cookie may be expired, invalid, scoped to another domain, or insufficient without related local or session storage. Fix: Validate an authenticated page or request and let session setup run again when validation fails. Check the cookie’s domain and the application’s actual authentication requirements.
Rank #4
The session setup succeeds but page commands run on the wrong page
Cause: Session restoration does not mean the test is already on the page it needs. Fix: Visit the target route after cy.session(), then interact with the page.
Recommended Free Tools
One spec works, another does not reuse the session
Cause: Cross-spec caching is limited to the same cypress run on the same machine, or the session definitions differ. Fix: Use cacheAcrossSpecs: true consistently and match the ID, setup, validation, and options. Do not expect a parallel worker or a new run to inherit the in-memory cache.
Tests pass in a suite but fail individually
Cause: A test relies on browser state left by another test, often because isolation was disabled. Fix: Give each test its own setup using cy.session() or cy.setCookie(). Keep disabled isolation only where ordering is deliberately part of the scenario.
Performance, reliability, and test cost
Session reuse can avoid repeating an expensive UI login for every test while preserving test isolation. A direct cy.request() login setup, as shown above, can avoid navigating through the login UI, but it tests the API-based authentication setup rather than the visible login form. Keep at least the tests that specifically cover the login interface responsible for exercising that interface.
For reliable suites, make setup repeatable, validate restored state, and ensure each test can run by itself. Cross-spec caching can reduce repeated setup on a single machine in a single run, but parallel CI machines and fresh runs need their own session setup. Avoid using a shared, order-dependent browser context as a shortcut for session management.
Or skip the browser setup
If your task is capturing a page screenshot rather than testing Cypress cookie persistence, ScreenshotNeo is a website screenshot API and MCP server. A single request can capture a URL as PNG, JPEG, WebP, or PDF. For example, this cURL command saves a WebP screenshot:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for parameters and response details. Cookie banners are accepted like a visitor and removed along with supported consent platforms, newsletter popups, and chat widgets before the shot; each step can be turned off. Bot checks, blank pages, and failed loads are never billed, and responses identify the page verdict and billing status. Its MCP server lets AI agents use screenshot tools. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up free for 1,000 screenshots a month, with no card required.
Frequently Asked Questions
Does cy.session() preserve cookies or just local storage?
It preserves and restores cookies, localStorage, and sessionStorage captured during setup.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Can Cypress share a session across parallel CI workers?
No. Cross-spec session caching applies to spec files in one run on the same machine; it is not shared with parallel machines.
Should I use cy.setCookie() to log in?
Only if the application genuinely accepts a known cookie value as sufficient. For server-created authentication state, use cy.session() and validate the resulting session.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

