Skip to content

Commit 7d06243

Browse files
committed
[js] Fix a handful of errors encountered with the edge driver
1. findElements will return a NoSuchElementError if nothing is found. Catch this and return an empty list 2. remote.DriverService tries to connect to the loopback address by default, but EdgeDriver binds host to "localhost" by default. We cannot make the driver bind to the loopback address without admin privileges, so change the client to just connect to localhost
1 parent 3394e30 commit 7d06243

6 files changed

Lines changed: 32 additions & 7 deletions

File tree

javascript/node/selenium-webdriver/edge.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ class ServiceBuilder {
280280
var args = this.args_.concat(); // Defensive copy.
281281

282282
return new remote.DriverService(this.exe_, {
283-
loopback: true,
283+
// Binding to the loopback address will fail if not running with
284+
// administrator privileges. Since we cannot test for that in script
285+
// (or can we?), force the DriverService to use "localhost".
286+
hostname: 'localhost',
284287
port: port,
285288
args: promise.fulfilled(port).then(function(port) {
286289
return args.concat('--port=' + port);

javascript/node/selenium-webdriver/example/logging.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ var driver = new webdriver.Builder()
3434
.build();
3535

3636
driver.get('http://www.google.com/ncr');
37-
driver.findElement(By.name('q')).sendKeys('webdriver');
37+
38+
var searchBox = driver.wait(until.elementLocated(By.name('q')), 3000);
39+
searchBox.sendKeys('webdriver');
40+
3841
driver.findElement(By.name('btnG')).click();
3942
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
4043
driver.quit();

javascript/node/selenium-webdriver/http/util.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ function getStatus(url) {
4242
var executor = new Executor(client);
4343
var command = new Command(CommandName.GET_SERVER_STATUS);
4444
return executor.execute(command).then(function(responseObj) {
45-
console.log('GOT HERE GOT HERE GOT HERE');
46-
console.dir(responseObj);
4745
error.checkLegacyResponse(responseObj);
4846
return responseObj['value'];
4947
});

javascript/node/selenium-webdriver/lib/test/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var build = require('./build'),
3434
*/
3535
var NATIVE_BROWSERS = [
3636
webdriver.Browser.CHROME,
37+
webdriver.Browser.EDGE,
3738
webdriver.Browser.FIREFOX,
3839
webdriver.Browser.IE,
3940
webdriver.Browser.OPERA,
@@ -59,6 +60,9 @@ var browsersToTest = (function() {
5960
if (parts[0] === 'ie') {
6061
parts[0] = webdriver.Browser.IE;
6162
}
63+
if (parts[0] === 'edge') {
64+
parts[0] = webdriver.Browser.EDGE;
65+
}
6266
return parts.join(':');
6367
});
6468
browsers.forEach(function(browser) {

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,13 @@ class WebDriver {
894894
let cmd = new command.Command(command.Name.FIND_ELEMENTS).
895895
setParameter('using', locator.using).
896896
setParameter('value', locator.value);
897-
return this.schedule(cmd, 'WebDriver.findElements(' + locator + ')');
897+
let res = this.schedule(cmd, 'WebDriver.findElements(' + locator + ')');
898+
return res.thenCatch(function(e) {
899+
if (e instanceof error.NoSuchElementError) {
900+
return [];
901+
}
902+
throw e;
903+
});
898904
}
899905
}
900906

javascript/node/selenium-webdriver/remote/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const httpUtil = require('../http/util'),
4040
*
4141
* - `loopback` - Whether the service should only be accessed on this host's
4242
* loopback address.
43+
* - `hostname` - The host name to access the server on. If this option is
44+
* specified, the `loopback` option will be ignored.
4345
* - `port` - The port to start the server on (must be > 0). If the port is
4446
* provided as a promise, the service will wait for the promise to resolve
4547
* before starting.
@@ -54,6 +56,7 @@ const httpUtil = require('../http/util'),
5456
*
5557
* @typedef {{
5658
* loopback: (boolean|undefined),
59+
* hostname: (string|undefined),
5760
* port: (number|!promise.Promise<number>),
5861
* args: !(Array<string>|promise.Promise<!Array<string>>),
5962
* path: (string|undefined|null),
@@ -85,6 +88,9 @@ class DriverService {
8588
/** @private {boolean} */
8689
this.loopbackOnly_ = !!options.loopback;
8790

91+
/** @private {(string|undefined)} */
92+
this.hostname_ = options.hostname;
93+
8894
/** @private {(number|!promise.Promise<number>)} */
8995
this.port_ = options.port;
9096

@@ -183,10 +189,15 @@ class DriverService {
183189
throw error;
184190
});
185191

192+
var hostname = self.hostname_;
193+
if (!hostname) {
194+
hostname = !self.loopbackOnly_ && net.getAddress()
195+
|| net.getLoopbackAddress();
196+
}
197+
186198
var serverUrl = url.format({
187199
protocol: 'http',
188-
hostname: !self.loopbackOnly_ && net.getAddress() ||
189-
net.getLoopbackAddress(),
200+
hostname: hostname,
190201
port: port,
191202
pathname: self.path_
192203
});

0 commit comments

Comments
 (0)