From 7721cfa65d7dda7f4ec5459763198ec2a46b285e Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Mon, 26 Oct 2015 16:07:24 -0700 Subject: [PATCH] Add {get,set}CookieValue --- lib/browser/cookie.js | 14 ++++++++++++++ test/integration/cookie.test.js | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/browser/cookie.js b/lib/browser/cookie.js index a82e5e8..cecc8cf 100644 --- a/lib/browser/cookie.js +++ b/lib/browser/cookie.js @@ -10,6 +10,20 @@ exports.clearCookies = function clearCookies() { return this.deleteAllCookies(); }; +exports.setCookieValue = function setCookieValue(name, value, options) { + var cookie = _.extend({ + name: name, + value: value, + path: '/', + secure: false, + }, options || {}); + return this.setCookie(cookie); +}; + +exports.getCookieValue = function getCookieValue(name) { + return this.getCookie(name).then(_.property('value')); +}; + exports.setCookies = function setCookies(cookies) { return Bluebird.all(cookies.map(this.setCookie, this)); }; diff --git a/test/integration/cookie.test.js b/test/integration/cookie.test.js index 879fec3..9240bcf 100644 --- a/test/integration/cookie.test.js +++ b/test/integration/cookie.test.js @@ -50,4 +50,22 @@ describe('cookie', () => { const cookie = await browser.getCookie('test_cookie'); assert.falsey(cookie); }); + + describe('setCookieValue', () => { + before(() => + browser + .navigateTo('/some/nested/url') + .setCookie({ name: 'non_root', value: 'a' }) + .setCookieValue('root', 'b') + .navigateTo('/')); + + it('can\'t read the non-root cookie', async () => { + assert.falsey(await browser.getCookie('non_root')); + }); + + it('can read the root cookie', async () => { + assert.truthy(await browser.getCookie('root')); + assert.equal('b', await browser.getCookieValue('root')); + }); + }); });