Skip to content

Commit 6c3110a

Browse files
committed
[javascript] Deprecating Channel
[skip ci]
1 parent eeaebe6 commit 6c3110a

File tree

1 file changed

+49
-55
lines changed

1 file changed

+49
-55
lines changed

javascript/node/selenium-webdriver/firefox.js

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,19 @@
6363
*
6464
* For Linux, Firefox will always be located on the PATH: `$(where firefox)`.
6565
*
66-
* Several methods are provided for starting Firefox with a custom executable.
67-
* First, on Windows and MacOS, you may configure WebDriver to check the default
68-
* install location for a non-release channel. If the requested channel cannot
69-
* be found in its default location, WebDriver will fallback to searching your
70-
* PATH. _Note:_ on Linux, Firefox is _always_ located on your path, regardless
71-
* of the requested channel.
66+
* You can provide a custom location for Firefox by setting the binary in the
67+
* {@link Options}:setBinary method.
7268
*
7369
* const {Builder} = require('selenium-webdriver');
7470
* const firefox = require('selenium-webdriver/firefox');
7571
*
76-
* let options = new firefox.Options().setBinary(firefox.Channel.NIGHTLY);
72+
* let options = new firefox.Options()
73+
* .setBinary('/my/firefox/install/dir/firefox');
7774
* let driver = new Builder()
7875
* .forBrowser('firefox')
7976
* .setFirefoxOptions(options)
8077
* .build();
8178
*
82-
* On all platforms, you may configure WebDriver to use a Firefox specific
83-
* executable:
84-
*
85-
* let options = new firefox.Options()
86-
* .setBinary('/my/firefox/install/dir/firefox-bin');
87-
*
8879
* __Remote Testing__
8980
*
9081
* You may customize the Firefox binary and profile when running against a
@@ -102,7 +93,7 @@
10293
*
10394
* let options = new firefox.Options()
10495
* .setProfile('/profile/path/on/remote/host')
105-
* .setBinary('/install/dir/on/remote/host/firefox-bin');
96+
* .setBinary('/install/dir/on/remote/host/firefox');
10697
*
10798
* let driver = new Builder()
10899
* .forBrowser('firefox')
@@ -136,7 +127,7 @@ const FIREFOX_CAPABILITY_KEY = 'moz:firefoxOptions'
136127
*/
137128
class AddonFormatError extends Error {
138129
/** @param {string} msg The error message. */
139-
constructor(msg) {
130+
constructor (msg) {
140131
super(msg)
141132
/** @override */
142133
this.name = this.constructor.name
@@ -150,7 +141,7 @@ class AddonFormatError extends Error {
150141
* @return {!Promise<string>} A promise for the add-on ID once
151142
* installed.
152143
*/
153-
async function installExtension(extension, dir) {
144+
async function installExtension (extension, dir) {
154145
const ext = extension.slice(-4)
155146
if (ext !== '.xpi' && ext !== '.zip') {
156147
throw Error('File name does not end in ".zip" or ".xpi": ' + ext)
@@ -188,23 +179,23 @@ async function installExtension(extension, dir) {
188179
}
189180

190181
class Profile {
191-
constructor() {
182+
constructor () {
192183
/** @private {?string} */
193184
this.template_ = null
194185

195186
/** @private {!Array<string>} */
196187
this.extensions_ = []
197188
}
198189

199-
addExtensions(/** !Array<string> */ paths) {
190+
addExtensions (/** !Array<string> */ paths) {
200191
this.extensions_ = this.extensions_.concat(...paths)
201192
}
202193

203194
/**
204195
* @return {(!Promise<string>|undefined)} a promise for a base64 encoded
205196
* profile, or undefined if there's no data to include.
206197
*/
207-
[Symbols.serialize]() {
198+
[Symbols.serialize] () {
208199
if (this.template_ || this.extensions_.length) {
209200
return buildProfile(this.template_, this.extensions_)
210201
}
@@ -218,7 +209,7 @@ class Profile {
218209
* profile.
219210
* @return {!Promise<string>} a promise for the base64 encoded profile.
220211
*/
221-
async function buildProfile(template, extensions) {
212+
async function buildProfile (template, extensions) {
222213
let dir = template
223214

224215
if (extensions.length) {
@@ -254,7 +245,7 @@ class Options extends Capabilities {
254245
* @param {(Capabilities|Map<string, ?>|Object)=} other Another set of
255246
* capabilities to initialize this instance from.
256247
*/
257-
constructor(other) {
248+
constructor (other) {
258249
super(other)
259250
this.setBrowserName(Browser.FIREFOX)
260251
}
@@ -263,7 +254,7 @@ class Options extends Capabilities {
263254
* @return {!Object}
264255
* @private
265256
*/
266-
firefoxOptions_() {
257+
firefoxOptions_ () {
267258
let options = this.get(FIREFOX_CAPABILITY_KEY)
268259
if (!options) {
269260
options = {}
@@ -276,7 +267,7 @@ class Options extends Capabilities {
276267
* @return {!Profile}
277268
* @private
278269
*/
279-
profile_() {
270+
profile_ () {
280271
let options = this.firefoxOptions_()
281272
if (!options.profile) {
282273
options.profile = new Profile()
@@ -291,7 +282,7 @@ class Options extends Capabilities {
291282
* @param {...(string|!Array<string>)} args The arguments to include.
292283
* @return {!Options} A self reference.
293284
*/
294-
addArguments(...args) {
285+
addArguments (...args) {
295286
if (args.length) {
296287
let options = this.firefoxOptions_()
297288
options.args = options.args ? options.args.concat(...args) : args
@@ -307,12 +298,13 @@ class Options extends Capabilities {
307298
* @throws {TypeError} if width or height is unspecified, not a number, or
308299
* less than or equal to 0.
309300
*/
310-
windowSize({ width, height }) {
311-
function checkArg(arg) {
301+
windowSize ({ width, height }) {
302+
function checkArg (arg) {
312303
if (typeof arg !== 'number' || arg <= 0) {
313304
throw TypeError('Arguments must be {width, height} with numbers > 0')
314305
}
315306
}
307+
316308
checkArg(width)
317309
checkArg(height)
318310
return this.addArguments(`--width=${width}`, `--height=${height}`)
@@ -324,7 +316,7 @@ class Options extends Capabilities {
324316
* @param {...string} paths The paths to the extension XPI files to install.
325317
* @return {!Options} A self reference.
326318
*/
327-
addExtensions(...paths) {
319+
addExtensions (...paths) {
328320
this.profile_().addExtensions(paths)
329321
return this
330322
}
@@ -335,7 +327,7 @@ class Options extends Capabilities {
335327
* @return {!Options} A self reference.
336328
* @throws {TypeError} if either the key or value has an invalid type.
337329
*/
338-
setPreference(key, value) {
330+
setPreference (key, value) {
339331
if (typeof key !== 'string') {
340332
throw TypeError(`key must be a string, but got ${typeof key}`)
341333
}
@@ -363,7 +355,7 @@ class Options extends Capabilities {
363355
* @return {!Options} A self reference.
364356
* @throws {TypeError} if profile is not a string.
365357
*/
366-
setProfile(profile) {
358+
setProfile (profile) {
367359
if (typeof profile !== 'string') {
368360
throw TypeError(`profile must be a string, but got ${typeof profile}`)
369361
}
@@ -373,18 +365,18 @@ class Options extends Capabilities {
373365

374366
/**
375367
* Sets the binary to use. The binary may be specified as the path to a
376-
* Firefox executable or a desired release {@link Channel}.
368+
* Firefox executable.
377369
*
378-
* @param {(string|!Channel)} binary The binary to use.
370+
* @param {(string)} binary The binary to use.
379371
* @return {!Options} A self reference.
380372
* @throws {TypeError} If `binary` is an invalid type.
381373
*/
382-
setBinary(binary) {
374+
setBinary (binary) {
383375
if (binary instanceof Channel || typeof binary === 'string') {
384376
this.firefoxOptions_().binary = binary
385377
return this
386378
}
387-
throw TypeError('binary must be a string path or Channel object')
379+
throw TypeError('binary must be a string path ')
388380
}
389381

390382
/**
@@ -393,7 +385,7 @@ class Options extends Capabilities {
393385
* @param {string} androidPackage The package to use
394386
* @return {!Options} A self reference
395387
*/
396-
enableMobile(
388+
enableMobile (
397389
androidPackage = 'org.mozilla.firefox',
398390
androidActivity = null,
399391
deviceSerial = null
@@ -412,15 +404,15 @@ class Options extends Capabilities {
412404
/**
413405
* Enables moz:debuggerAddress for firefox cdp
414406
*/
415-
enableDebugger() {
407+
enableDebugger () {
416408
return this.set('moz:debuggerAddress', true)
417409
}
418410

419411
/**
420412
* Enable bidi connection
421413
* @returns {!Capabilities}
422414
*/
423-
enableBidi() {
415+
enableBidi () {
424416
return this.set('webSocketUrl', true)
425417
}
426418
}
@@ -446,7 +438,7 @@ const Context = {
446438
* @return {!Promise<?string>} A promise for the located executable.
447439
* The promise will resolve to {@code null} if Firefox was not found.
448440
*/
449-
function findInProgramFiles(file) {
441+
function findInProgramFiles (file) {
450442
let files = [
451443
process.env['PROGRAMFILES'] || 'C:\\Program Files',
452444
process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)',
@@ -455,8 +447,8 @@ function findInProgramFiles(file) {
455447
return exists
456448
? files[0]
457449
: io.exists(files[1]).then(function (exists) {
458-
return exists ? files[1] : null
459-
})
450+
return exists ? files[1] : null
451+
})
460452
})
461453
}
462454

@@ -473,7 +465,7 @@ const ExtensionCommand = {
473465
* @param {!Promise<string>} serverUrl The server's URL.
474466
* @return {!command.Executor} The new command executor.
475467
*/
476-
function createExecutor(serverUrl) {
468+
function createExecutor (serverUrl) {
477469
let client = serverUrl.then((url) => new http.HttpClient(url))
478470
let executor = new http.Executor(client)
479471
configureExecutor(executor)
@@ -484,7 +476,7 @@ function createExecutor(serverUrl) {
484476
* Configures the given executor with Firefox-specific commands.
485477
* @param {!http.Executor} executor the executor to configure.
486478
*/
487-
function configureExecutor(executor) {
479+
function configureExecutor (executor) {
488480
executor.defineCommand(
489481
ExtensionCommand.GET_CONTEXT,
490482
'GET',
@@ -520,7 +512,7 @@ class ServiceBuilder extends remote.DriverService.Builder {
520512
* @param {string=} opt_exe Path to the server executable to use. If omitted,
521513
* the builder will attempt to locate the geckodriver on the system PATH.
522514
*/
523-
constructor(opt_exe) {
515+
constructor (opt_exe) {
524516
super(opt_exe)
525517
this.setLoopback(true) // Required.
526518
}
@@ -532,7 +524,7 @@ class ServiceBuilder extends remote.DriverService.Builder {
532524
* default, only debug logging is enabled.
533525
* @return {!ServiceBuilder} A self reference.
534526
*/
535-
enableVerboseLogging(opt_trace) {
527+
enableVerboseLogging (opt_trace) {
536528
return this.addArguments(opt_trace ? '-vv' : '-v')
537529
}
538530
}
@@ -563,7 +555,7 @@ class Driver extends webdriver.WebDriver {
563555
* configured to use the legacy FirefoxDriver from the Selenium project.
564556
* @return {!Driver} A new driver instance.
565557
*/
566-
static createSession(opt_config, opt_executor) {
558+
static createSession (opt_config, opt_executor) {
567559
let caps =
568560
opt_config instanceof Capabilities ? opt_config : new Options(opt_config)
569561

@@ -612,14 +604,14 @@ class Driver extends webdriver.WebDriver {
612604
* implementation.
613605
* @override
614606
*/
615-
setFileDetector() {}
607+
setFileDetector () {}
616608

617609
/**
618610
* Get the context that is currently in effect.
619611
*
620612
* @return {!Promise<Context>} Current context.
621613
*/
622-
getContext() {
614+
getContext () {
623615
return this.execute(new command.Command(ExtensionCommand.GET_CONTEXT))
624616
}
625617

@@ -637,7 +629,7 @@ class Driver extends webdriver.WebDriver {
637629
*
638630
* @param {!Promise<void>} ctx The context to switch to.
639631
*/
640-
setContext(ctx) {
632+
setContext (ctx) {
641633
return this.execute(
642634
new command.Command(ExtensionCommand.SET_CONTEXT).setParameter(
643635
'context',
@@ -660,7 +652,7 @@ class Driver extends webdriver.WebDriver {
660652
* newly installed addon.
661653
* @see #uninstallAddon
662654
*/
663-
async installAddon(path, temporary = false) {
655+
async installAddon (path, temporary = false) {
664656
let stats = fs.statSync(path)
665657
let buf
666658
if (stats.isDirectory()) {
@@ -685,7 +677,7 @@ class Driver extends webdriver.WebDriver {
685677
* completed.
686678
* @see #installAddon
687679
*/
688-
async uninstallAddon(id) {
680+
async uninstallAddon (id) {
689681
id = await Promise.resolve(id)
690682
return this.execute(
691683
new command.Command(ExtensionCommand.UNINSTALL_ADDON).setParameter(
@@ -700,15 +692,17 @@ class Driver extends webdriver.WebDriver {
700692
* Provides methods for locating the executable for a Firefox release channel
701693
* on Windows and MacOS. For other systems (i.e. Linux), Firefox will always
702694
* be located on the system PATH.
703-
*
695+
* @deprecated Instead of using this class, you should configure the
696+
* {@link Options} with the appropriate binary location or let Selenium
697+
* Manager handle it for you.
704698
* @final
705699
*/
706700
class Channel {
707701
/**
708702
* @param {string} darwin The path to check when running on MacOS.
709703
* @param {string} win32 The path to check when running on Windows.
710704
*/
711-
constructor(darwin, win32) {
705+
constructor (darwin, win32) {
712706
/** @private @const */ this.darwin_ = darwin
713707
/** @private @const */ this.win32_ = win32
714708
/** @private {Promise<string>} */
@@ -724,7 +718,7 @@ class Channel {
724718
* @return {!Promise<string>} A promise for the location of the located
725719
* Firefox executable.
726720
*/
727-
locate() {
721+
locate () {
728722
if (this.found_) {
729723
return this.found_
730724
}
@@ -759,7 +753,7 @@ class Channel {
759753
}
760754

761755
/** @return {!Promise<string>} */
762-
[Symbols.serialize]() {
756+
[Symbols.serialize] () {
763757
return this.locate()
764758
}
765759
}
@@ -782,7 +776,7 @@ Channel.DEV = new Channel(
782776
* @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#beta>
783777
*/
784778
Channel.BETA = new Channel(
785-
'/Applications/Firefox.app/Contents/MacOS/firefox-bin',
779+
'/Applications/Firefox.app/Contents/MacOS/firefox',
786780
'Mozilla Firefox\\firefox.exe'
787781
)
788782

@@ -792,7 +786,7 @@ Channel.BETA = new Channel(
792786
* @see <https://www.mozilla.org/en-US/firefox/desktop/>
793787
*/
794788
Channel.RELEASE = new Channel(
795-
'/Applications/Firefox.app/Contents/MacOS/firefox-bin',
789+
'/Applications/Firefox.app/Contents/MacOS/firefox',
796790
'Mozilla Firefox\\firefox.exe'
797791
)
798792

0 commit comments

Comments
 (0)