Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions javascript/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const zip = require('./io/zip')
const { Browser, Capabilities, Capability } = require('./lib/capabilities')
const { Zip } = require('./io/zip')
const { getBinaryPaths } = require('./common/driverFinder')
const { findFreePort } = require('./net/portprober')
const FIREFOX_CAPABILITY_KEY = 'moz:firefoxOptions'

/**
Expand Down Expand Up @@ -505,6 +506,31 @@ class ServiceBuilder extends remote.DriverService.Builder {
enableVerboseLogging(opt_trace) {
return this.addArguments(opt_trace ? '-vv' : '-v')
}

/**
* Overrides the parent build() method to add the websocket port argument
* for Firefox when not connecting to an existing instance.
*
* @return {!DriverService} A new driver service instance.
*/
build() {
let port = this.options_.port || findFreePort()
let argsPromise = Promise.resolve(port).then((port) => {
// Start with the default --port argument.
let args = this.options_.args.concat(`--port=${port}`)
// If the "--connect-existing" flag is not set, add the websocket port.
if (!this.options_.args.some((arg) => arg === '--connect-existing')) {
return findFreePort().then((wsPort) => {
args.push(`--websocket-port=${wsPort}`)
return args
})
}
return args
})

let options = Object.assign({}, this.options_, { args: argsPromise, port })
return new remote.DriverService(this.exe_, options)
}
}

/**
Expand Down
Loading