Files
enviPy-bayer/static/js/ketcher2/node_modules/webdriverio/lib/commands/getCookie.js
2025-06-23 20:13:54 +02:00

54 lines
1.4 KiB
JavaScript

/**
*
* Retrieve a [cookie](https://w3c.github.io/webdriver/webdriver-spec.html#cookies)
* visible to the current page. You can query a specific cookie by providing the cookie name or
* retrieve all.
*
* <example>
:getCookie.js
it('should return a cookie for me', function () {
browser.setCookie({name: 'test', value: '123'})
browser.setCookie({name: 'test2', value: '456'})
var testCookie = browser.getCookie('test')
console.log(testCookie); // outputs: { name: 'test', value: '123' }
var allCookies = browser.getCookie()
console.log(allCookies);
// outputs:
// [
// { name: 'test', value: '123' },
// { name: 'test2', value: '456' }
// ]
})
* </example>
*
* @alias browser.getCookie
* @param {String=} name name of requested cookie
* @return {Object|null} requested cookie if existing
* @uses protocol/cookie
* @type cookie
*
*/
let getCookie = function (name) {
/*!
* paramter check
*/
if (typeof name !== 'string') {
name = null
}
return this.cookie().then((res) => {
res.value = res.value || []
if (typeof name === 'string') {
return res.value.filter((cookie) => cookie.name === name)[0] || null
}
return res.value || (typeof name === 'string' ? null : [])
})
}
export default getCookie