Files
cypress/docs/source/api/commands/getcookies.md
Brian Mann 91bb010fd6 docs: fixes #231, cleanup all the API docs + notes
- go into more detail on trigger vs action commands
- explain actionability further
- better format notes + examples
- consistent no arg / arg examples
- es6 all the functions
- remove duplicated intractability content
- remove simulated events garbage
- go into more detail on pseudo action commands
- much better cy.contains usage
2017-06-30 18:33:52 -04:00

2.3 KiB

title, comments
title comments
getCookies false

Get all of the browser cookies.

Syntax

cy.getCookies()
cy.getCookies(options)

Usage

{% fa fa-check-circle green %} Correct Usage

cy.getCookies()    // Get all cookies

Arguments

{% fa fa-angle-right %} options (Object)

Pass in an options object to change the default behavior of cy.getCookies().

Option Default Description
log true {% usage_options log %}
timeout {% url responseTimeout configuration#Timeouts %} {% usage_options timeout cy.getCookies %}

Yields {% helper_icon yields %}

cy.getCookies() yields an array of cookie objects. Each cookie object has the following properties:

  • name
  • value
  • path
  • domain
  • httpOnly
  • secure
  • expiry

Examples

Get Cookies

Get cookies after logging in

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

// assume we just logged in
cy.contains('Login').click()
cy.url().should('include', 'profile')
cy.getCookies()
  .should('have.length', 1)
  .then(function(cookies) {
    expect(cookies[0]).to.have.property('name', 'session_id')
  })

Rules

Requirements {% helper_icon requirements %}

{% requirements parent cy.getCookies %}

Assertions {% helper_icon assertions %}

{% assertions once cy.getCookies %}

Timeouts {% helper_icon timeout %}

{% timeouts automation cy.getCookies %}

Command Log

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

The commands above will display in the command log as:

Command Log

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

Console Log

See also

  • {% url cy.clearCookie() clearcookie %}
  • {% url cy.clearCookies() clearcookies %}
  • {% url 'Cypress Cookies API' cookies %}
  • {% url cy.getCookie() getcookie %}
  • {% url cy.setCookie() setcookie %}