webdriverio-workflo
Version:
This is a customized version of webdriverio for use with workflo framework.
61 lines (53 loc) • 1.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
*
* 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
*
*/
var getCookie = function getCookie(name) {
/*!
* parameter check
*/
if (typeof name !== 'string') {
name = null;
}
return this.cookie().then(function (res) {
res.value = res.value || [];
if (typeof name === 'string') {
return res.value.filter(function (cookie) {
return cookie.name === name;
})[0] || null;
}
return res.value || (typeof name === 'string' ? null : []);
});
};
exports.default = getCookie;
module.exports = exports['default'];
;