Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/5hai/nightwatch into featur…
Browse files Browse the repository at this point in the history
…es/support-for-context-for-hybrid-mobile-apps
  • Loading branch information
beatfactor committed Jul 17, 2015
2 parents f652a83 + 9b56108 commit 40e1308
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/api/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,45 @@ module.exports = function(Nightwatch) {
Actions.source = function(callback) {
return getRequest('/source', callback);
};



//////////////////////////////////////////////////////////////////
// Context related
//////////////////////////////////////////////////////////////////

/**
* Get a list of the available contexts.
*
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @jsonWire GET /session/:sessionId/contexts
*/
Actions.contexts = function(callback) {
return getRequest('/contexts', callback);
};

/**
*
* Get current context.
*
* @jsonWire GET /session/:sessionId/contexts
*/
Actions.currentContext = function(callback) {
return getRequest('/context', callback);
};

/**
* Set context.
*
* @param {string} context name switch to
* @jsonWire POST /session/:sessionId/context
*/
Actions.setContext = function (contextRef, callback) {
var data = { name: contextRef };
return postRequest('/context', data, callback);
};



//////////////////////////////////////////////////////////////////
// Mouse related
Expand Down
44 changes: 44 additions & 0 deletions tests/src/testProtocolActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,51 @@ module.exports = {
test.equal(command.request.path, '/wd/hub/session/1352110219202/log/types');
});
},
/////////////////////////////


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

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

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

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

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

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


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

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

test.equal(command.request.method, 'POST');
test.equal(command.data, '{"name":"Context text"}');
test.equal(command.request.path, '/wd/hub/session/1352110219202/context');
});
},


tearDown : function(callback) {
this.client = null;
// clean up
Expand Down

0 comments on commit 40e1308

Please sign in to comment.