# Cookies

Examples of managing cookies in Cypress, for a full reference of commands, go to docs.cypress.io

#### Cypress.Cookies.set()

To set a cookie key, value, use `Cypress.Cookies.set()`.

    Cypress.Cookies.set('fakeCookie', '123ABC')

    cy.document().its('cookie').should('include', 'fakeCookie=123ABC')

#### Cypress.Cookies.get()

To get a cookie by its key, use `Cypress.Cookies.get()`.

    Cypress.Cookies.set('fakeCookie', '123ABC')

    expect(Cypress.Cookies.get('fakeCookie')).to.eq('123ABC')

#### Cypress.Cookies.remove()

To remove a cookie by its key, use `Cypress.Cookies.remove()`.

    Cypress.Cookies.set('fakeCookie', '123ABC')
    expect(Cypress.Cookies.get('fakeCookie')).to.eq('123ABC')

    Cypress.Cookies.remove('fakeCookie')
    expect(Cypress.Cookies.get('fakeCookie')).to.not.be.ok

#### Cypress.Cookies.debug()

To enable or disable cookie debugging, use `Cypress.Cookies.debug()`.

    // Cypress will now log in the console when
    // cookies are set or removed
    Cypress.Cookies.debug(true)

    Cypress.Cookies.set('fakeCookie', '123ABC')
    Cypress.Cookies.remove('fakeCookie')
    Cypress.Cookies.set('fakeCookie', '123ABC')
    Cypress.Cookies.remove('fakeCookie')
    Cypress.Cookies.set('fakeCookie', '123ABC')

#### Cypress.Cookies.preserveOnce()

To preserve cookies by its key, use `Cypress.Cookies.preserveOnce()`.

    expect(Cypress.Cookies.get('fakeCookie')).to.not.be.ok

    Cypress.Cookies.set('lastCookie', '789XYZ')
    Cypress.Cookies.preserveOnce('lastCookie')

#### Cypress.Cookies.default()

To set defaults for all cookies, use `Cypress.Cookies.default()`.

    Cypress.Cookies.defaults({
      whitelist: "session_id"
    })