Skip to content

Commit 395bd72

Browse files
committed
JavaScript client side support for launch_app command of chromedriver:
/session/$sessionId/chromium/launch_app This is related to pull request #168
1 parent 1b6febd commit 395bd72

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

javascript/node/selenium-webdriver/chrome.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var fs = require('fs'),
119119

120120
var webdriver = require('./index'),
121121
executors = require('./executors'),
122+
http = require('./http'),
122123
io = require('./io'),
123124
portprober = require('./net/portprober'),
124125
remote = require('./remote');
@@ -133,6 +134,32 @@ var CHROMEDRIVER_EXE =
133134
process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver';
134135

135136

137+
/**
138+
* Custom command names supported by ChromeDriver.
139+
* @enum {string}
140+
*/
141+
var Command = {
142+
LAUNCH_APP: 'launchApp'
143+
};
144+
145+
146+
/**
147+
* Creates a command executor with support for ChromeDriver's custom commands.
148+
* @param {!webdriver.promise.Promise<string>} url The server's URL.
149+
* @return {!webdriver.CommandExecutor} The new command executor.
150+
*/
151+
function createExecutor(url) {
152+
return new executors.DeferredExecutor(url.then(function(url) {
153+
var client = new http.HttpClient(url);
154+
var executor = new http.Executor(client);
155+
executor.defineCommand(
156+
Command.LAUNCH_APP,
157+
'POST', '/session/:sessionId/chromium/launch_app');
158+
return executor;
159+
}));
160+
}
161+
162+
136163
/**
137164
* Creates {@link selenium-webdriver/remote.DriverService} instances that manage
138165
* a [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/)
@@ -774,7 +801,7 @@ Options.prototype.serialize = function() {
774801
*/
775802
var Driver = function(opt_config, opt_service, opt_flow) {
776803
var service = opt_service || getDefaultService();
777-
var executor = executors.createExecutor(service.start());
804+
var executor = createExecutor(service.start());
778805

779806
var capabilities =
780807
opt_config instanceof Options ? opt_config.toCapabilities() :
@@ -798,6 +825,19 @@ Driver.prototype.setFileDetector = function() {
798825
};
799826

800827

828+
/**
829+
* Schedules a command to launch Chrome App with given ID.
830+
* @param {string} id ID of the App to launch.
831+
* @return {!webdriver.promise.Promise<void>} A promise that will be resolved
832+
* when app is launched.
833+
*/
834+
Driver.prototype.launchApp = function(id) {
835+
return this.schedule(
836+
new webdriver.Command(Command.LAUNCH_APP).setParameter('id', id),
837+
'Driver.launchApp()');
838+
};
839+
840+
801841
// PUBLIC API
802842

803843

0 commit comments

Comments
 (0)