View Source Improve this doc

setCookie

Sets a cookie for current page. Make sure you are on the page that should receive the cookie. You can’t set a cookie for an arbitrary page without being on that page.

Usage

1
browser.setCookie(cookie,cookie.name,cookie.value,cookie.path,cookie.domain,cookie.secure,cookie.httpOnly,cookie.expiry);

Parameters

Param Type Details
cookie Object cookie object
cookie.name String The name of the cookie
cookie.value String The cookie value
cookie.path String (Optional) The cookie path
cookie.domain String (Optional) The domain the cookie is visible to
cookie.secure Boolean (Optional) Whether the cookie is a secure cookie
cookie.httpOnly Boolean (Optional) Whether the cookie is an httpOnly cookie
cookie.expiry Number (Optional) When the cookie expires, specified in seconds since midnight, January 1, 1970 UTC

Example

setCookie.js
1
2
3
4
5
6
7
it('should set a cookie for the page', function () {
browser.url('/')
browser.setCookie({name: 'test', value: '123'});

var cookies = browser.getCookie();
console.log(cookies); // outputs: [{ name: 'test', value: '123', domain: 'www.example.com' }]
});

Uses