Skip to content

Commit

Permalink
[js] Finalise JS Binding support for WebDriver Bidi in Firefox
Browse files Browse the repository at this point in the history
This requires Firefox 87 and Geckodriver 0.29 to be able to work
  • Loading branch information
AutomatedTester committed Feb 11, 2021
1 parent 10b1603 commit bdeac8e
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ build --test_env=SELENIUM_BROWSER
build --test_env=TRAVIS

test --test_timeout=1800

test:node_debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pkg_npm(
],
)

TEST_FILES = glob(["test/**/*_test.js"])
TEST_FILES = ["test/**/*_test.js"]

TEST_DATA = SRC_FILES + glob(
[
Expand Down
8 changes: 2 additions & 6 deletions javascript/node/selenium-webdriver/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class Options extends Capabilities {
return extension.toString('base64')
}
return io
.read(/** @type {string} */ (extension))
.read(/** @type {string} */(extension))
.then((buffer) => buffer.toString('base64'))
})
}
Expand Down Expand Up @@ -618,7 +618,7 @@ class Driver extends webdriver.WebDriver {
* implementation.
* @override
*/
setFileDetector() {}
setFileDetector() { }

/**
* Schedules a command to launch Chrome App with given ID.
Expand Down Expand Up @@ -820,10 +820,6 @@ class Driver extends webdriver.WebDriver {
'Driver.stopCasting(' + deviceName + ')'
)
}

getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
}

// PUBLIC API
Expand Down
50 changes: 9 additions & 41 deletions javascript/node/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async function buildProfile(template, extensions) {
dir = await io.tmpDir()
if (template) {
await io.copyDir(
/** @type {string} */ (template),
/** @type {string} */(template),
dir,
/(parent\.lock|lock|\.parentlock)/
)
Expand Down Expand Up @@ -433,11 +433,11 @@ function findGeckoDriver() {
if (!exe) {
throw Error(
'The ' +
GECKO_DRIVER_EXE +
' executable could not be found on the current ' +
'PATH. Please download the latest version from ' +
'https://github.com/mozilla/geckodriver/releases/ ' +
'and ensure it can be found on your PATH.'
GECKO_DRIVER_EXE +
' executable could not be found on the current ' +
'PATH. Please download the latest version from ' +
'https://github.com/mozilla/geckodriver/releases/ ' +
'and ensure it can be found on your PATH.'
)
}
return exe
Expand All @@ -458,8 +458,8 @@ function findInProgramFiles(file) {
return exists
? files[0]
: io.exists(files[1]).then(function (exists) {
return exists ? files[1] : null
})
return exists ? files[1] : null
})
})
}

Expand Down Expand Up @@ -593,7 +593,7 @@ class Driver extends webdriver.WebDriver {
* implementation.
* @override
*/
setFileDetector() {}
setFileDetector() { }

/**
* Get the context that is currently in effect.
Expand Down Expand Up @@ -667,38 +667,6 @@ class Driver extends webdriver.WebDriver {
)
)
}

/**
* Creates a new WebSocket connection.
* @return {!Promise<resolved>} A new CDP instance.
*/
async createCDPConnection(target) {
const caps = await this.getCapabilities()
const seOptions = caps['map_'].get('se:options') || new Map()
const vendorInfo =
caps['map_'].get('moz:debuggerAddress') ||
new Map()
const debuggerUrl = seOptions['cdp'] || vendorInfo['debuggerAddress']
this._wsUrl = await this.getWsUrl(debuggerUrl, target)

return new Promise((resolve, reject) => {
try {
this._wsConnection = new WebSocket(this._wsUrl)
} catch (err) {
reject(err)
return
}

this._wsConnection.on('open', () => {
this._cdpConnection = new cdp.CdpConnection(this._wsConnection)
resolve(this._cdpConnection)
})

this._wsConnection.on('error', (error) => {
reject(error)
})
})
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/lib/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const Platform = {
*
* @record
*/
function Timeouts() {}
function Timeouts() { }

/**
* Defines when, in milliseconds, to interrupt a script that is being
Expand Down Expand Up @@ -264,7 +264,7 @@ class Capabilities {
* @return {!Capabilities} A basic set of capabilities for Firefox.
*/
static firefox() {
return new Capabilities().setBrowserName(Browser.FIREFOX)
return new Capabilities().setBrowserName(Browser.FIREFOX).set("moz:debuggerAddress", true)
}

/**
Expand Down
Loading

0 comments on commit bdeac8e

Please sign in to comment.