Files
cypress/docs/source/api/commands/setcookie.md
T

2.3 KiB

title, comments, description
title comments description
setcookie true

Set a browser cookie.

Returns a cookie object
Timeout cy.setCookie will wait up for the duration of responseTimeout for the automation server to process this command.

cy.setCookie( name, value )

Sets a browser cookie.

Options

Pass in an options object to change the default behavior of cy.setCookie.

cy.setCookie( name, value, options )

Option Default Notes
path / the cookie path
domain window.location.hostname the domain the cookie is visible to
secure false whether the cookie is a secure cookie
httpOnly false whether the cookie is an HTTP only cookie
expiry 20 years into the future when the cookie expires, specified in seconds since Unix Epoch.
timeout responseTimeout Total time to wait for the cy.setCookie command to be processed
log true whether to display command in command log

Usage

cy
  .getCookies().should('be.empty')
  .setCookie('session_id', '189jd09sufh33aaiidhf99d09')
  .getCookie('session_id').should('have.property', 'value', '189jd09sufh33aaiidhf99d09')

Command Log

cy
  .getCookies().should('be.empty')
  .setCookie('fakeCookie1', '123ABC')
  .getCookie('fakeCookie1').should('have.property', 'value', '123ABC')

The commands above will display in the command log as:

screen shot 2016-05-10 at 12 15 53 pm

When clicking on setCookie within the command log, the console outputs the following:

screen shot 2016-05-10 at 12 16 01 pm

Related