forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request webdriverio#117 from christian-bromann/issue/117
Implement protocol binding for DELETE /session/:sessionId/cookie
- Loading branch information
Showing
5 changed files
with
82 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
module.exports = function deleteCookie (name, callback) { | ||
|
||
if(typeof name == 'function') { | ||
if(typeof name === 'function') { | ||
callback = name; | ||
name = null; | ||
} | ||
|
||
var requestOptions = { | ||
path: '/session/:sessionId/cookie' + (name ? '/:name' : ''), | ||
method: 'DELETE' | ||
}; | ||
this.cookie('DELETE', name, function(err,result) { | ||
|
||
var self = this; | ||
|
||
if(name) { | ||
requestOptions.path = requestOptions.path.replace(/:name/, name); | ||
} | ||
|
||
this.requestHandler.create(requestOptions,{},callback); | ||
if(typeof callback === 'function') { | ||
callback(err, result); | ||
} | ||
|
||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
module.exports = function setCookie (cookieObj, callback) { | ||
this.cookie(cookieObj, function(err, result) { | ||
callback(err, result && result.value); | ||
|
||
// throw error if no cookie object is given | ||
if(typeof cookieObj !== 'object') { | ||
throw 'Please specify a cookie object to set (see http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object for documentation.'; | ||
} | ||
|
||
this.cookie('POST', cookieObj, function(err, result) { | ||
|
||
if(typeof callback === 'function') { | ||
callback(err, result && result.value); | ||
} | ||
|
||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
module.exports = function cookie (cookieObj, callback) { | ||
/** | ||
* protocol bindings for all cookie operations | ||
* @ref http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/cookie | ||
*/ | ||
|
||
if(typeof cookieObj === 'function') { | ||
callback = cookieObj; | ||
cookieObj = null; | ||
} | ||
module.exports = function cookie (method, args, callback) { | ||
|
||
// set default options | ||
var data = {}, | ||
requestOptions = { | ||
path: '/session/:sessionId/cookie', | ||
method: method.toUpperCase() | ||
}; | ||
|
||
var requestOptions = { | ||
path: '/session/:sessionId/cookie', | ||
method: cookieObj ? 'POST' : 'GET' | ||
}; | ||
|
||
if(cookieObj && !('secure' in cookieObj)) { | ||
cookieObj.secure = false; | ||
// set cookie param for POST method | ||
if(requestOptions.method === 'POST' && typeof args === 'object') { | ||
data.cookie = args; | ||
} | ||
|
||
var data = cookieObj ? { cookie: cookieObj } : {}; | ||
// add cookie name tp path URL to delete a specific cookie object | ||
if(requestOptions.method === 'DELETE' && typeof args === 'string') { | ||
requestOptions.path += '/' + args; | ||
} | ||
|
||
// create request | ||
this.requestHandler.create(requestOptions,data,callback); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
/*module.exports = function(testpageURL,testpageTitle,assert,should,expect){ | ||
describe.only('test cookie functionality',function() { | ||
before(h.setup); | ||
|
||
describe('test cookie functionality',function() { | ||
it('should set a cookie and read its content afterwards', function(done){ | ||
client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.getCookie('test', function(err,result) { | ||
assert.equal(null, err) | ||
assert.strictEqual(result.name,'test'); | ||
assert.strictEqual(result.value,'cookie saved!'); | ||
}) | ||
.call(done); | ||
}); | ||
it('should delete created cookie and is not able to read its content', function(done){ | ||
client | ||
.deleteCookie('test') | ||
.getCookie('test', function(err,result) { | ||
assert.equal(null, err) | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
}); | ||
it('should set a cookie and read its content afterwards', function(done){ | ||
this.client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.getCookie('test', function(err,result) { | ||
assert.equal(null, err); | ||
assert.strictEqual(result.name,'test'); | ||
assert.strictEqual(result.value,'cookie saved!'); | ||
}) | ||
.call(done); | ||
}); | ||
|
||
it('should create two cookies and delete all at once', function(done){ | ||
client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.setCookie({name: 'test2',value: 'cookie2 saved!'}) | ||
.deleteCookie() | ||
.getCookie('test', function(err,result) { | ||
assert.equal(null, err) | ||
assert.strictEqual(result,null); | ||
}) | ||
.getCookie('test2', function(err,result) { | ||
assert.equal(null, err) | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
}); | ||
it('should delete created cookie and is not able to read its content', function(done){ | ||
this.client | ||
.deleteCookie('test') | ||
.getCookie('test', function(err,result) { | ||
assert.equal(null, err); | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
}); | ||
|
||
it('should set two cookies and read all at once', function(done){ | ||
this.client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.setCookie({name: 'test2',value: 'cookie2 saved!'}) | ||
.getCookie(function(err,result) { | ||
assert.equal(null, err); | ||
assert.strictEqual(2,result.length); | ||
assert.strictEqual('cookie saved!',result[0].value); | ||
assert.strictEqual('cookie2 saved!',result[1].value); | ||
}) | ||
.call(done); | ||
}); | ||
|
||
};*/ | ||
it('should delete all previous created cookies at once', function(done){ | ||
this.client | ||
.deleteCookie() | ||
.getCookie(function(err,result) { | ||
assert.equal(null, err); | ||
assert.strictEqual(0,result.length); | ||
}) | ||
.call(done); | ||
}); | ||
}); |