getCookies
Overview
Use the getCookies
command to get all or specific cookies on the current page.
To get specific cookies, you need to specify the cookie name as a string or a list of cookie names as an array of strings.
Usage
await browser.getCookies(names);
Command Parameters
Name | Type | Description |
names | String or String[] | Optional parameter. The name of the cookie or list of cookie names to get. If the parameter is missing, all cookies for the current page will be returned. |
Usage Examples
it("should return a cookie for me", async ({ browser }) => {
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' }
// ]
});
Related Commands
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.