Skip to content

Commit 6afcf11

Browse files
committed
[JS] Add websocket port option in Firefox ServiceBuilder when '--connect-existing' is not passed
1 parent bf0c427 commit 6afcf11

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

javascript/selenium-webdriver/firefox.js

+26
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const zip = require('./io/zip')
121121
const { Browser, Capabilities, Capability } = require('./lib/capabilities')
122122
const { Zip } = require('./io/zip')
123123
const { getBinaryPaths } = require('./common/driverFinder')
124+
const { findFreePort } = require('./net/portprober')
124125
const FIREFOX_CAPABILITY_KEY = 'moz:firefoxOptions'
125126

126127
/**
@@ -505,6 +506,31 @@ class ServiceBuilder extends remote.DriverService.Builder {
505506
enableVerboseLogging(opt_trace) {
506507
return this.addArguments(opt_trace ? '-vv' : '-v')
507508
}
509+
510+
/**
511+
* Overrides the parent build() method to add the websocket port argument
512+
* for Firefox when not connecting to an existing instance.
513+
*
514+
* @return {!DriverService} A new driver service instance.
515+
*/
516+
build() {
517+
let port = this.options_.port || findFreePort();
518+
let argsPromise = Promise.resolve(port).then((port) => {
519+
// Start with the default --port argument.
520+
let args = this.options_.args.concat(`--port=${port}`);
521+
// If the "--connect-existing" flag is not set, add the websocket port.
522+
if (!this.options_.args.some(arg => arg === '--connect-existing')) {
523+
return findFreePort().then(wsPort => {
524+
args.push(`--websocket-port=${wsPort}`);
525+
return args;
526+
});
527+
}
528+
return args;
529+
});
530+
531+
let options = Object.assign({}, this.options_, { args: argsPromise, port });
532+
return new remote.DriverService(this.exe_, options);
533+
}
508534
}
509535

510536
/**

0 commit comments

Comments
 (0)