Skip to content

Commit

Permalink
Fixed issues with get session command added post support to session #287
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Apr 19, 2015
1 parent ed1576e commit 04f8027
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/api/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module.exports = function(Nightwatch) {
// Session related
//////////////////////////////////////////////////////////////////
/**
* Get info about or delete the current session.
* Get info about, delete the current session or create a new session.
*
* @link /session
* @param {string} action The http method to use, can be get or delete
* @param {string} [action] The http verb to use, can be "get", "post" or "delete". If only the callback is passed, get is assumed as default.
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol
*/
Expand All @@ -27,17 +27,26 @@ module.exports = function(Nightwatch) {
if (typeof arguments[0] === 'function') {
callback = arguments[0];
action = 'get';
} else {
action = action.toLowerCase();
}

switch (action) {
case 'delete':
options.path += '/' + Nightwatch.sessionId;
options.method = 'DELETE';
break;
case 'post':
options.method = 'POST';
break;
default:
options.method = 'GET';
}

if (action != 'post') {
options.path += '/' + Nightwatch.sessionId;
}


return sendRequest(options, callback);
};

Expand Down
56 changes: 56 additions & 0 deletions tests/src/testProtocolActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,62 @@ module.exports = {
});
},

testSessionGET : function(test) {
var client = this.client;
var protocol = this.protocol;

this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.session(function callback() {
test.done();
});

test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202');
});
},

testSessionDefault : function(test) {
var client = this.client;
var protocol = this.protocol;

this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.session('GET', function callback() {
test.done();
});

test.equal(command.request.method, 'GET');
test.equal(command.request.path, '/wd/hub/session/1352110219202');
});
},

testSessionDELETE : function(test) {
var client = this.client;
var protocol = this.protocol;

this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.session('DELETE', function callback() {
test.done();
});

test.equal(command.request.method, 'DELETE');
test.equal(command.request.path, '/wd/hub/session/1352110219202');
});
},

testSessionPOST : function(test) {
var client = this.client;
var protocol = this.protocol;

this.client.on('selenium:session_create', function(sessionId) {
var command = protocol.session('POST', function callback() {
test.done();
});

test.equal(command.request.method, 'POST');
test.equal(command.request.path, '/wd/hub/session');
});
},

testScreenshot : function(test) {
var client = this.client;
var protocol = this.protocol;
Expand Down

0 comments on commit 04f8027

Please sign in to comment.