Skip to content

Commit

Permalink
Added a basic ServiceBuilder for Internet Explorer (#6181)
Browse files Browse the repository at this point in the history
* Added a basic ServiceBuilder for Internet Explorer

Adds it to IE's `Driver` and allows it to be specified with a new `setIeService` in the general `Builder`.

Fixes #5983

* Added IE service
  • Loading branch information
Josh Goldberg authored and jleyba committed Aug 3, 2018
1 parent 0c561b6 commit b39ea54
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
31 changes: 29 additions & 2 deletions javascript/node/selenium-webdriver/ie.js
Expand Up @@ -360,6 +360,23 @@ function createServiceFromCapabilities(capabilities) {
}


/**
* Creates {@link selenium-webdriver/remote.DriverService} instances that manage
* an [IEDriverServer](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver)
* server in a child process.
*/
class ServiceBuilder extends remote.DriverService.Builder {
/**
* @param {string=} opt_exe Path to the server executable to use. If omitted,
* the builder will attempt to locate the IEDriverServer on the system PATH.
*/
constructor(opt_exe) {
super(opt_exe || IEDRIVER_EXE);
this.setLoopback(true); // Required.
}
}


/**
* A WebDriver client for Microsoft's Internet Explorer.
*/
Expand All @@ -368,12 +385,21 @@ class Driver extends webdriver.WebDriver {
* Creates a new session for Microsoft's Internet Explorer.
*
* @param {(Capabilities|Options)=} options The configuration options.
* @param {(remote.DriverService)=} opt_service The `DriverService` to use
* to start the IEDriverServer in a child process, optionally.
* @return {!Driver} A new driver instance.
*/
static createSession(options) {
static createSession(options, opt_service) {
options = options || new Options();

let service = createServiceFromCapabilities(options);
let service;

if (opt_service instanceof remote.DriverService) {
service = opt_service;
} else {
service = createServiceFromCapabilities(options);
}

let client = service.start().then(url => new http.HttpClient(url));
let executor = new http.Executor(client);

Expand All @@ -396,5 +422,6 @@ class Driver extends webdriver.WebDriver {
exports.Driver = Driver;
exports.Options = Options;
exports.Level = Level;
exports.ServiceBuilder = ServiceBuilder;
exports.locateSynchronously = locateSynchronously;

21 changes: 20 additions & 1 deletion javascript/node/selenium-webdriver/index.js
Expand Up @@ -223,6 +223,9 @@ class Builder {

/** @private {ie.Options} */
this.ieOptions_ = null;

/** @private {ie.ServiceBuilder} */
this.ieService_ = null;

/** @private {safari.Options} */
this.safariOptions_ = null;
Expand Down Expand Up @@ -490,6 +493,18 @@ class Builder {
return this;
}

/**
* Sets the {@link ie.ServiceBuilder} to use to manage the geckodriver
* child process when creating IE sessions locally.
*
* @param {ie.ServiceBuilder} service the service to use.
* @return {!Builder} a self reference.
*/
setIeService(service) {
this.ieService_ = service;
return this;
}

/**
* Set {@linkplain edge.Options options} specific to Microsoft's Edge browser
* for drivers created by this builder. Any proxy settings defined on the
Expand Down Expand Up @@ -656,7 +671,11 @@ class Builder {
}

case Browser.INTERNET_EXPLORER:
return createDriver(ie.Driver, capabilities);
let service = null;
if (this.ieService_) {
service = this.ieService_.build();
}
return createDriver(ie.Driver, capabilities, service);

case Browser.EDGE: {
let service = null;
Expand Down

0 comments on commit b39ea54

Please sign in to comment.