Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] Add websocket port option in Firefox ServiceBuilder when '--connect-existing' is not passed #15557

Merged
merged 2 commits into from
Apr 3, 2025
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