How to Clear Cache between tests in Cypress
Related Product On This Page What does Cypress Cache include?June 18, 2026 · 7 min read · Tool Comparison
If you are act on creating web applications, you are using biscuit, local storage, and session storage. When you use JavaScript to make your web applications, you use all three mechanisms to store information on the client. These means of storing information impact your testing methodology. No matter the type of testing that you are execute –,, penetration testing,, etc, you will need to take with these mechanisms. Your or must run on a clear machine to feign the unparalleled test instance they cater to. Different Types of Cache Storage How to clear the cache between tests in Cypress This guide explains how to clear Cypress hoard through various method and the best practices associated with it. The Cypress cache stores files that assistant rush up examination tally and avoid repeated downloads. It typically include: Default Cache Location: Understand each of these mechanics. Cookies are used to save info about the user, such as name, parole, and settings. The storage capacity is limited to a few kilobytes of data. Cookies are a good option for store data that should not be stored for a long clip, such as session IDs. Data is sent with the client & # 8217; s request to the server. Data is store only in the browser. Session storage is a type of web depot that allow web applications to store datum topically in the user & # 8217; s browser. Unlike cookies, the information and datum stored in session memory are specific to the website for which it was created and is not share with other site. Data is stored solely for the duration of the session and is deleted when the browser is closed. Session memory is useful for storing sensitive information such as login credentials. Information is not send to the server at the asking of the customer. Data is stored only in the browser. Local storage is a type of online storage that allow JavaScript to store and access information straight in the browser. This is especially utilitarian if you salve info that you want to proceed yet when the exploiter closes the browser (e.g. setting or preferences). In-memory data is store as key/value pairs. The key is like the name of the information, and the value is like the datum itself. You can reckon of it as a JavaScript variable. To relieve data to local depot, you must first return a key. You can so store the information you need under that key. Saved data is not blue-pencil when closing the browser. This is especially useful if you save information that you desire to keep even when the exploiter closes the browser (e.g. scene or preferences). Information is not sent to the waiter at the request of the client. The datum is stored in the browser and the system. For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. Read More: By nonpayment, Cypress mechanically clears the cache between tests, namely cookies, local depot, and session storage, to prevent the state from build up. You can conserve session details across tests using thecy.session () command. Though Cypress automatically clears cookies, local storage, and session storage before each test, it also cater specific commands in cause you & # 8217; re habituate it to clear a specific cookie inside a single test or exam isolation is disable. Also Read: Use the next examples to see how Cypress brighten each of the test data with the commands. The following script opens amazon.com and let cookies. After you run thecy.clearCookies ()command, you can see that the cookie storehouse is empty. The undermentioned image establish the answer of thecy.getCookies ()command returning an regalia of 8 objects, while after clearing cookies, an empty raiment is render. Though Cypress unclutter local storage between tests, you will see how to unclutter local store intentionally. The undermentioned book out-of-doorsamazon.comand asserts to assure that the local entrepot is not empty. After you run thecy.clearLocalStorage ()command, the affirmation to see that the local storage is empty verifies itself. The following image shows the result of thecy.clearLocalStorage ()bid resulting in the asseveration be verified. You can get discussing with our dissension community The undermentioned playscript opens thehttps: //www.bstackdemo.com/signinpage and signaling in with a valid username and password. After thecy.clearAllSessionStorage ()bid executes and the script tries to open the same page, the page requests for the credentials again. The undermentioned image establish the signed-in user when credentials are entered: After the cy.clearAllSessionStorage ()command executes, the following sign-in page seem: Read More: While Cypress provides in-test commands likecy.clearCookies () or cy.clearLocalStorage ()to readjust browser-level hoard during test test, there are situations where you need to clearCypress & # 8217; s internal cache, such as cached binaries, download versions, or corrupted installs. This is handled using theCypress CLI cache command. Command: bash Some of the best practices that you must remark when using these three commands are: Running Cypress test topically or on in-house substructure get with limitations—restricted OS and browser coverage, high maintenance, and circumscribed scalability. BrowserStack Automate provides a robust, cloud-based solution to defeat these challenges. This article excuse how Cypress has the inbuilt ability to clear stash data between test run in a single spec file. Though Cypress is robust and offers ease of creating tests, it does limit the reach of browser and device that you can test in real-time position. For stable examination, you must and for that employ a, such as, is a great option. Access to multiple devices helps you predict and manage matter before your product reaches production. provides access to an array of web browsers and OS for you to test your covering. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
How to Clear Cache between tests in Cypress
Overview
What does Cypress Cache include?
~/.cache/Cypress
% LOCALAPPDATA % \Cypress\Cache
Different Types of Cache Storage
Cookies
Session Storage
Local Storage
Cache depot in Cypress
How to unclutter the cache between tests in Cypress
Method 1: Using cy.clearCookies () bid
it ('Browserstack cookie ', () = & gt; {cy.visit ('https: //www.amazon.com ') cy.wait (10000) cy.getCookies () .should ('not.be.empty ') cy.clearCookies () cy.getCookies () .should ('be.empty ')})Method 2: Using cy.clearLocalStorage () command
it ('Browserstack local storage ', () = & gt; {cy.visit ('https: //www.amazon.com ') cy.wait (10000) cy.getAllLocalStorage () .should ('not.be.empty ') cy.clearLocalStorage () cy.getAllLocalStorage () .should ('be.empty ')})Like what you are reading?
Method 3: cy.clearAllSessionStorage () bidding
it ('BstackDemo clear session storage ', () = & gt; {cy.visit ('https: //www.bstackdemo.com/signin/ ') cy.get (`` # username '') .click (); cy.xpath (`` //div [text () ='demouser '] '') .click (); cy.get (`` # password '') .click (); cy.xpath (`` //div [textbook () ='testingisfun99 '] '') .click (); cy.get (`` # login-btn '') .click (); cy.wait (5000); cy.clearAllSessionStorage ({log: true}) cy.visit ('https: //www.bstackdemo.com/signin/ ')})Method 4: Cypress CLI Command to Clear Cache
npx cypress hoard open
Good Practices for clearing cache between examination in Cypress
Why choose BrowserStack to run Cypress Tests?
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously