How to use Cypress Clear Cookies Command?
On This Page How do Cypress cookies work?April 01, 2026 · 4 min read · Tool Comparison
Before become started, let us interpret what cookies are. Cookies are pieces of information that are stored by websites in our browsers. This information will be utilized by the various websites based on their need. Sometimes there may be a motive to unclutter those biscuit to screen a website. Cypress runner/browser get use of cookies to store user-related information. By default, removes the cookies before executing the script. But sometimes, we may involve to brighten our cookies in between while executing our trial script. Cypress has render the undermentioned bid to clear our biscuit manually: We can pass arguments and clear cookies establish on our needs. Each of the three dictation has its intent. We will look into it with more details below. Learn More: ? For some test scenarios, we may need to log in with multiple exploiter in the same domain for a which might need to clear our biscuit to achieve it. Let ’ s see how Cypress clears cookies between tests from our script. Cypress mechanisation make it rattling simple and easy to clear cookie with the below three commands: 1. For clearing one particular cookie 2. For clearing multiple cookie with specific domain 3. For clear all cookies across different domain For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users. _browserstack & # 8221;) Above bid clears the cooky named _gat_browserstack ain: & # 8217; browserstack.co m’,log: false, timeout:1 5000}) Above command clears all the cookies link to the domain browserstack.com g: true, timeout:15000}) Above bidding clears all the cooky across all the area Let ’ s get our hands dirty by executing the open cookies require We are now going to execute a script which could clear a single cooky Note: It is mandatory forcy.clearCookiepurpose to pass the argument as the name of the cookie. Without specifying the name of the cookie, the bid will fail. Always use clearCookie to clear any specific biscuit. Similarly, now let & # 8217; s clear all the cookies with a specific domain using clearCookies require Note:It is not mandatory to legislate options as argument. Suppose we want to clear all the cookies limiting to any specific domain. In that cause, we can simply usecy.clearCookies ()command without specifying any arguments that brighten all biscuit for the current domain. We are now going to clear all the cookies which got stored in cypress with clearAllCookies command, You can view the browser console log for the cooky which got store and cookies that are cleared while executing the open cooky bidding. Conclusion: With that, you might be able to realize how to clear a cookie/cookies in Cypress and where to useclearCookie, clearCookies,andclearAllCookiesbid. Also, the contention which we need to pass for all the command to use effectively. Cypress is an emerging examination fabric and can test it across multiple devices. Browserstack provides you with a racy base to prove on multiple devices with Cypress for # 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.How to use Cypress Clear Cookies Command?
How do Cypress cookies work?
Benefits of employ the Cypress Clear Cookies Command
Types of Cypress Clear Cookies Commands
cy.clearCookie (name, pick)
cy.clearCookies (options)
cy.clearAllCookies (choice)
Using Cypress Clear Cookies Command
Clear Cookie command Arguments Description Example clearCookie name, selection cy.clearCookie(& # 8220; _gat clearCookies options Options can feature below values in the signifier of object cy.clearCookies ({dom clearAllCookies options Options can have below values in the pattern of aim cy.clearAllCookies ({lo 1. Clearing a individual cooky with clearCookie command
describe ('template spec ', () = & gt; {it ('passes ', () = & gt; {//Visiting the browserstack website cy.visit ('https: //browserstack.com ') //Getting the list of cookies which are stored cy.getCookies () //Clearing the cookie named “ _get_browserstack ” cy.clearCookie (`` _gat_browserstack '') //Viewing the cookies back whether the compulsory cookie got deleted cy.getCookies ()})})2. Clearing Multiple Cookies for a Specific Domain
describe ('template spec ', () = & gt; {it ('passes ', () = & gt; {//Visiting browserstack website cy.visit ('https: //browserstack.com ') //Getting the leaning of cookies which on stored in browser cy.getCookies () //Clearing the cooky with specific domain cy.clearCookies ({domain: 'browserstack.com ', log: true, timeout:15000}) //Getting all the cookies list currently available cy.getCookies ()})})3. Clearing Multiple Cookies for all the Domains
describe ('template spec ', () = & gt; {it ('passes ', () = & gt; {//Visiting browserstack website cy.visit ('https: //browserstack.com ') //Getting the list of cookies which on store in browser cy.getCookies () //Clearing all the cookies cy.clearAllCookies () //Getting all the cookie list currently available cy.getCookies ()})})Viewing more detail from the Cypress smuggler
Related Guides
Automate This With SUSA
Test Your App Autonomously