@testim/testim-cli
Version:
Command line interface for running Testing on you CI
53 lines (44 loc) • 1.54 kB
JavaScript
/**
* Protocol binding to operate with cookies on the current page.
*
* <example>
:cookie.js
// get all cookies
client.cookie(function(err,res) { ... });
// set cookie
client.cookie('post', {
name: 'myCookie',
value: 'some content'
});
// delete cookie
client.cookie('delete','myCookie');
* </example>
*
* @param {String=} method request method
* @param {Object=|String=} args contains cookie information if you want to set a cookie or contains name of cookie if you want to delete it
*
* @returns {Object} cookie data
*
* @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie
* @see https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie/:name
* @type protocol
*
*/
module.exports = function cookie (method, args) {
// set default options
var data = {},
requestOptions = {
path: '/session/:sessionId/cookie',
method: typeof method === 'string' ? method : 'GET'
};
// set cookie param for POST method
if(typeof method === 'string' && method.toUpperCase() === 'POST' && typeof args === 'object') {
data.cookie = args;
}
// add cookie name tp path URL to delete a specific cookie object
if(typeof method === 'string' && method.toUpperCase() === 'DELETE' && typeof args === 'string') {
requestOptions.path += '/' + args;
}
// create request
return this.requestHandler.create(requestOptions, data);
};