Cypress Cookies API

Profile picture for user arilio666

When there is a need to monitor any changes in the cookies, there is a command called cookies.debug(), which makes life easier by generating logs to the console whenever cookies are modified.

Syntax:

Cypress.Cookies.debug(enable, options)

Arguments Used:

enable: It should be paired up with a boolean whether the debugging should be enabled.
options: verbose is used whether or not to display the entire cookie object default is true.

Example:

  • For example, we will be doing clearcookies, setting cookies, and checking whether debug captures it on the console.
  • For this programsbuzz login page will be used.
  • _ga cookie will be modified.
       cy.visit("https://www.programsbuzz.com/user/login")
 Cypress.Cookies.debug(true, { verbose: false })
       cy.clearCookie('_ga')
       cy.setCookie('_ga', '_ya')

 

  • By turning off the verbose, we can see how minimal the log has come to.
  • By default, cypress will log a cookie object which will allow us to inspect all of its properties that may be crowded.
  • With this, we can see the change happened alone.
       cy.visit("https://www.programsbuzz.com/user/login")
       Cypress.Cookies.debug(true)
       cy.clearCookie('_ga')
       cy.setCookie('_ga', '_ya')
  • Here is with verbose turned on. We can see the difference here between the two.
Cypress.Cookies.debug(false)
  • Making the enable false will discontinue monitoring in the console.