diff --git a/lib/api/protocol.js b/lib/api/protocol.js index d611c9970c..7e124fb063 100644 --- a/lib/api/protocol.js +++ b/lib/api/protocol.js @@ -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 diff --git a/tests/src/testProtocolActions.js b/tests/src/testProtocolActions.js index b07121eddb..6e81487057 100644 --- a/tests/src/testProtocolActions.js +++ b/tests/src/testProtocolActions.js @@ -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