cy.getCookie()

To get a browser cookie, use the cy.getCookie() command.

cy
  .get('.set-a-cookie').click()

  .getCookie('token').should('have.property', 'value', '123ABC')

cy.getCookies()

To get all browser cookies, use the cy.getCookies() command.

cy
  .getCookies().should('be.empty')

  .get('.set-a-cookie').click()

  .getCookies().should('have.length', 1).then( function(cookies) {
    expect(cookies[0]).to.have.property('name', 'token')
    expect(cookies[0]).to.have.property('value', '123ABC')
    expect(cookies[0]).to.have.property('httpOnly', false)
    expect(cookies[0]).to.have.property('secure', false)
    expect(cookies[0]).to.have.property('domain')
    expect(cookies[0]).to.have.property('path')
  })

cy.setCookie()

To set a browser cookie, use the cy.setCookie() command.

cy
  .getCookies().should('be.empty')

  .setCookie('foo', 'bar')

  // getCookie() returns a cookie object
  .getCookie('foo').should('have.property', 'value', 'bar')

cy.clearCookies()

To clear a browser cookie, use the cy.clearCookie() command.

cy
  .getCookie('token').should('be.null')

  .get('.set-a-cookie').click()

  .getCookie('token').should('have.property', 'value', '123ABC')

  .clearCookie('token').should('be.null')

  .getCookie('token').should('be.null')

cy.clearCookies()

To clear all browser cookies, use the cy.clearCookies() command.

cy
  .getCookies().should('be.empty')

  .get('.set-a-cookie').click()

  .getCookies().should('have.length', 1)

  .clearCookies()

  .getCookies().should('be.empty')