Skip to content

Commit 944aad2

Browse files
committed
[JS] Code cleanup and minor improvements
1 parent 22e458b commit 944aad2

22 files changed

Lines changed: 190 additions & 183 deletions

javascript/node/selenium-webdriver/chrome.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ Driver.getDefaultService = getDefaultService
286286
Driver.prototype.VENDOR_COMMAND_PREFIX = 'goog'
287287

288288
// PUBLIC API
289-
exports.Driver = Driver
290-
exports.Options = Options
291-
exports.ServiceBuilder = ServiceBuilder
292-
exports.getDefaultService = getDefaultService
293-
exports.setDefaultService = setDefaultService
294-
exports.locateSynchronously = locateSynchronously
289+
290+
module.exports = {
291+
Driver: Driver,
292+
Options,
293+
ServiceBuilder ,
294+
getDefaultService,
295+
setDefaultService,
296+
locateSynchronously
297+
}
298+

javascript/node/selenium-webdriver/chromium.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const Command = {
105105
/**
106106
* Creates a command executor with support for Chromium's custom commands.
107107
* @param {!Promise<string>} url The server's URL.
108+
* @param vendorPrefix
108109
* @return {!command.Executor} The new command executor.
109110
*/
110111
function createExecutor(url, vendorPrefix) {

javascript/node/selenium-webdriver/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ function startSeleniumServer(jar) {
7676
* @return {function(new: webdriver.WebDriver, ...?)}
7777
*/
7878
function ensureFileDetectorsAreEnabled(ctor) {
79-
const mixin = class extends ctor {
79+
return class extends ctor {
8080
/** @param {input.FileDetector} detector */
81-
setFileDetector(detector) {
81+
setFileDetector (detector) {
8282
webdriver.WebDriver.prototype.setFileDetector.call(this, detector)
8383
}
8484
}
85-
return mixin
8685
}
8786

8887
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function checkCodePoint(key) {
250250
}
251251

252252
key = key.normalize()
253-
if (Array.from(key).length != 1) {
253+
if (Array.from(key).length !== 1) {
254254
throw new InvalidArgumentError(
255255
`key input is not a single code point: ${key}`
256256
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ async function fullyResolveKeys(obj) {
262262
) {
263263
return
264264
}
265-
let resolvedValue = await fullyResolved(partialValue)
266-
obj[key] = resolvedValue
265+
obj[key] = await fullyResolved(partialValue)
267266
})
268267
return obj
269268
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,7 @@ class ShadowRootPromise extends ShadowRoot {
29942994
/**
29952995
* @param {!WebDriver} driver The parent WebDriver instance for this
29962996
* element.
2997-
* @param {!Promise<!ShadowRoot>} el A promise
2997+
* @param {!Promise<!ShadowRoot>} shadow A promise
29982998
* that will resolve to the promised element.
29992999
*/
30003000
constructor(driver, shadow) {

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ const portprober = require('../net/portprober')
3333
/**
3434
* @typedef {(string|!Array<string|number|!stream.Stream|null|undefined>)}
3535
*/
36-
var StdIoOptions // eslint-disable-line
36+
let StdIoOptions // eslint-disable-line
3737

3838
/**
3939
* @typedef {(string|!IThenable<string>)}
4040
*/
41-
var CommandLineFlag // eslint-disable-line
41+
let CommandLineFlag // eslint-disable-line
4242

4343
/**
4444
* A record object that defines the configuration options for a DriverService
@@ -196,8 +196,8 @@ class DriverService {
196196
return this.address_
197197
}
198198

199-
var timeout = opt_timeoutMs || DriverService.DEFAULT_START_TIMEOUT_MS
200-
var self = this
199+
const timeout = opt_timeoutMs || DriverService.DEFAULT_START_TIMEOUT_MS
200+
const self = this
201201

202202
let resolveCommand
203203
this.command_ = new Promise((resolve) => (resolveCommand = resolve))
@@ -567,7 +567,7 @@ SeleniumServer.Options = class {
567567
* When a file path on the local machine running this script is entered with
568568
* {@link webdriver.WebElement#sendKeys WebElement#sendKeys}, this file detector
569569
* will transfer the specified file to the Selenium server's host; the sendKeys
570-
* command will be updated to use the transfered file's path.
570+
* command will be updated to use the transferred file's path.
571571
*
572572
* __Note:__ This class depends on a non-standard command supported on the
573573
* Java Selenium server. The file detector will fail if used with a server that
@@ -618,7 +618,10 @@ class FileDetector extends input.FileDetector {
618618

619619
// PUBLIC API
620620

621-
exports.DriverService = DriverService
622-
exports.FileDetector = FileDetector
623-
exports.SeleniumServer = SeleniumServer
624-
exports.ServiceOptions = ServiceOptions // Exported for API docs.
621+
module.exports = {
622+
DriverService,
623+
FileDetector,
624+
SeleniumServer,
625+
// Exported for API docs.
626+
ServiceOptions
627+
}

javascript/node/selenium-webdriver/test/actions_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ test.suite(function (env) {
107107
// This appears to be a quirk of the timing around mocha tests and not
108108
// necessarily a bug in the chromedriver.
109109
// TODO(jleyba): dig into this more so we can remove this hack.
110-
describe('dragAndDrop()', function () {
111-
it('', async function () {
110+
// describe('dragAndDrop()', function () {
111+
it('dragAndDrop()', async function () {
112112
await driver.get(fileServer.whereIs('/data/actions/drag.html'))
113113

114114
let slide = await driver.findElement(By.id('slide'))
@@ -125,7 +125,7 @@ test.suite(function (env) {
125125
assert.strictEqual(await slide.getCssValue('left'), '206px')
126126
assert.strictEqual(await slide.getCssValue('top'), '1px')
127127
})
128-
})
128+
// })
129129

130130
it('move()', async function () {
131131
await driver.get(fileServer.whereIs('/data/actions/drag.html'))

javascript/node/selenium-webdriver/test/chrome/devtools_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.suite(
3838
.setChromeOptions(new chrome.Options().headless())
3939
.build()
4040
})
41-
after(() => driver.quit())
41+
after(async () => await driver.quit())
4242

4343
it('can send commands to devtools', async function () {
4444
await driver.get(test.Pages.ajaxyPage)

javascript/node/selenium-webdriver/test/chrome/options_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ test.suite(
145145

146146
describe('Chrome options', function () {
147147
it('can start Chrome with custom args', async function () {
148-
var options = new chrome.Options().addArguments('user-agent=foo;bar')
148+
const options = new chrome.Options().addArguments('user-agent=foo;bar')
149149

150150
driver = await env.builder().setChromeOptions(options).build()
151151

152152
await driver.get(test.Pages.ajaxyPage)
153153

154-
var userAgent = await driver.executeScript(
154+
const userAgent = await driver.executeScript(
155155
'return window.navigator.userAgent'
156156
)
157157
assert.strictEqual(userAgent, 'foo;bar')

0 commit comments

Comments
 (0)