getCookies
Retrieve a cookie visible to the current page. You can query a specific cookie by providing the cookie name or retrieve all.
Usage
browser.getCookies(names)
Parameters
Name | Type | Details |
---|---|---|
names optional | Array.<String> , String | names of requested cookies (if omitted, all cookies will be returned) |
Example
- Asynchronous Mode
- Synchronous Mode
getCookies.js
it('should return a cookie for me', async () => {
await browser.setCookies([
{name: 'test', value: '123'},
{name: 'test2', value: '456'}
])
const testCookie = await browser.getCookies(['test'])
console.log(testCookie); // outputs: [{ name: 'test', value: '123' }]
const allCookies = await browser.getCookies()
console.log(allCookies);
// outputs:
// [
// { name: 'test', value: '123' },
// { name: 'test2', value: '456' }
// ]
})
getCookies.js
it('should return a cookie for me', () => {
browser.setCookies([
{name: 'test', value: '123'},
{name: 'test2', value: '456'}
])
const testCookie = browser.getCookies(['test'])
console.log(testCookie); // outputs: [{ name: 'test', value: '123' }]
const allCookies = browser.getCookies()
console.log(allCookies);
// outputs:
// [
// { name: 'test', value: '123' },
// { name: 'test2', value: '456' }
// ]
})
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.