Files
cypress/docs/source/api/commands/getcookie.md
T
2017-05-23 17:17:27 -04:00

2.6 KiB

title, comments, description
title comments description
getcookie true

Get a browser cookie.

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

cy.getCookie( name )

Gets a browser cookie by its name.

This object will have the following properties:

Properties
name
value
path
domain
httpOnly
secure
expiry

Options

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

cy.getCookie( name, options )

Option Default Notes
timeout responseTimeout Total time to wait for the cy.getCookie command to be processed
log true whether to display command in command log

Usage

In this example, on first login our server sends us back a session cookie.

cy
  .login('bob@example.com', 'p@ssw0rd') // example of a custom command
  .getCookie('session_id')
    .should('have.property', 'value', '189jd09sufh33aaiidhf99d09')

{% note info Using cy.getCookie to test login %} Check out our example recipes using cy.getCookie to test logging in using HTML web forms, logging in using XHR web forms and logging in with single sign on {% endnote %}

Command Log

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

The commands above will display in the command log as:

screen shot 2016-05-10 at 12 12 13 pm

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

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

See also