Skip to content

Commit 13c8499

Browse files
committed
[js] Clean-up from the removal of the legacy FirefoxDriver.
- Removed firefox.ServiceBuilder#setFirefoxBinary(); custom binaries should be configured through the firefox.Options class. - Removed firefox.Capability - Simplify internal code
1 parent 7c29034 commit 13c8499

File tree

3 files changed

+68
-177
lines changed

3 files changed

+68
-177
lines changed

javascript/node/selenium-webdriver/CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
- nativeEventsEnabled
1717
- getPort
1818
- setPort
19+
* Removed `selenium-webdriver/firefox.ServiceBuilder#setFirefoxBinary()`; custom
20+
binaries should be configured through the `firefox.Options` class.
21+
* Removed `selenium-webdriver/firefox.Capability`. These hold overs from the
22+
legacy FirefoxDriver are no longer supported.
1923

2024
### Changes for W3C WebDriver Spec Compliance
2125

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

+64-158
Original file line numberDiff line numberDiff line change
@@ -137,35 +137,6 @@ const {Binary, Channel} = require('./binary'),
137137
remote = require('../remote');
138138

139139

140-
/**
141-
* Firefox-specific capability keys. Users should use the {@linkplain Options}
142-
* class instead of referencing these keys directly. _These keys are considered
143-
* implementation details and may be removed or changed at any time._
144-
*
145-
* @enum {string}
146-
*/
147-
const Capability = {
148-
/**
149-
* Defines the Firefox binary to use. May be set to either a
150-
* {@linkplain Binary} instance, or a string path to the Firefox executable.
151-
*/
152-
BINARY: 'firefox_binary',
153-
154-
/**
155-
* @deprecated This will be removed in a future release. There is no
156-
* replacement.
157-
*/
158-
MARIONETTE: 'marionette',
159-
160-
/**
161-
* Defines the Firefox profile to use. May be set to either a
162-
* {@linkplain Profile} instance, or to a base-64 encoded zip of a profile
163-
* directory.
164-
*/
165-
PROFILE: 'firefox_profile'
166-
};
167-
168-
169140
/**
170141
* Configuration options for the FirefoxDriver.
171142
*/
@@ -174,7 +145,7 @@ class Options {
174145
/** @private {Profile} */
175146
this.profile_ = null;
176147

177-
/** @private {Binary} */
148+
/** @private {(Binary|Channel|string|null)} */
178149
this.binary_ = null;
179150

180151
/** @private {logging.Preferences} */
@@ -210,17 +181,14 @@ class Options {
210181
* @throws {TypeError} If `binary` is an invalid type.
211182
*/
212183
setBinary(binary) {
213-
if (typeof binary === 'string' || binary instanceof Channel) {
214-
binary = new Binary(binary);
184+
if (binary instanceof Binary
185+
|| binary instanceof Channel
186+
|| typeof binary === 'string') {
187+
this.binary_ = binary;
188+
return this;
215189
}
216-
217-
if (!(binary instanceof Binary)) {
218-
throw TypeError(
219-
'binary must be a string path, Channel, or Binary object');
220-
}
221-
222-
this.binary_ = binary;
223-
return this;
190+
throw TypeError(
191+
'binary must be a string path, Channel, or Binary object');
224192
}
225193

226194
/**
@@ -250,19 +218,54 @@ class Options {
250218
* @return {!capabilities.Capabilities} A new capabilities object.
251219
*/
252220
toCapabilities() {
253-
var caps = capabilities.Capabilities.firefox();
221+
let caps = capabilities.Capabilities.firefox();
222+
let firefoxOptions = {};
223+
caps.set('moz:firefoxOptions', firefoxOptions);
224+
254225
if (this.logPrefs_) {
255226
caps.set(capabilities.Capability.LOGGING_PREFS, this.logPrefs_);
256227
}
228+
257229
if (this.proxy_) {
258230
caps.set(capabilities.Capability.PROXY, this.proxy_);
259231
}
232+
260233
if (this.binary_) {
261-
caps.set(Capability.BINARY, this.binary_);
234+
if (this.binary_ instanceof Binary) {
235+
let exe = this.binary_.getExe();
236+
if (exe) {
237+
firefoxOptions['binary'] = exe;
238+
}
239+
240+
let args = this.binary_.getArguments();
241+
if (args.length) {
242+
firefoxOptions['args'] = args;
243+
}
244+
} else if (this.binary_ instanceof Channel) {
245+
firefoxOptions['binary'] = this.binary_.locate();
246+
247+
} else if (typeof this.binary_ === 'string') {
248+
firefoxOptions['binary'] = this.binary_;
249+
}
262250
}
251+
263252
if (this.profile_) {
264-
caps.set(Capability.PROFILE, this.profile_);
253+
// If the user specified a template directory or any extensions to
254+
// install, we need to encode the profile as a base64 string (which
255+
// requires writing it to disk first). Otherwise, if the user just
256+
// specified some custom preferences, we can send those directly.
257+
let profile = this.profile_;
258+
if (profile.getTemplateDir() || profile.getExtensions().length) {
259+
firefoxOptions['profile'] = profile.encode();
260+
261+
} else {
262+
let prefs = profile.getPreferences();
263+
if (Object.keys(prefs).length) {
264+
firefoxOptions['prefs'] = prefs;
265+
}
266+
}
265267
}
268+
266269
return caps;
267270
}
268271
}
@@ -401,111 +404,6 @@ class ServiceBuilder extends remote.DriverService.Builder {
401404
enableVerboseLogging(opt_trace) {
402405
return this.addArguments(opt_trace ? '-vv' : '-v');
403406
}
404-
405-
/**
406-
* Sets the path to the executable Firefox binary that the geckodriver should
407-
* use. If this method is not called, this builder will attempt to locate
408-
* Firefox in the default installation location for the current platform.
409-
*
410-
* @param {(string|!Binary)} binary Path to the executable Firefox binary to use.
411-
* @return {!ServiceBuilder} A self reference.
412-
* @see Binary#locate()
413-
*/
414-
setFirefoxBinary(binary) {
415-
let exe = typeof binary === 'string'
416-
? Promise.resolve(binary) : binary.locate();
417-
return this.addArguments('-b', exe);
418-
}
419-
}
420-
421-
422-
/**
423-
* @typedef {{executor: !command.Executor,
424-
* capabilities: (!capabilities.Capabilities|
425-
* {desired: (capabilities.Capabilities|undefined),
426-
* required: (capabilities.Capabilities|undefined)}),
427-
* onQuit: function(this: void): ?}}
428-
*/
429-
var DriverSpec;
430-
431-
432-
/**
433-
* @param {(http.Executor|remote.DriverService|undefined)} executor
434-
* @param {!capabilities.Capabilities} caps
435-
* @param {Profile} profile
436-
* @param {Binary} binary
437-
* @return {DriverSpec}
438-
*/
439-
function createGeckoDriver(executor, caps, profile, binary) {
440-
let firefoxOptions = caps.get('moz:firefoxOptions') || {};
441-
caps.set('moz:firefoxOptions', firefoxOptions);
442-
443-
if (binary) {
444-
if (binary.getExe()) {
445-
firefoxOptions['binary'] = binary.getExe();
446-
}
447-
448-
let args = binary.getArguments();
449-
if (args.length) {
450-
firefoxOptions['args'] = args;
451-
}
452-
}
453-
454-
if (profile) {
455-
// If the user specified a template directory or any extensions to install,
456-
// we need to encode the profile as a base64 string (which requires writing
457-
// it to disk first). Otherwise, if the user just specified some custom
458-
// preferences, we can send those directly.
459-
if (profile.getTemplateDir() || profile.getExtensions().length) {
460-
firefoxOptions['profile'] = profile.encode();
461-
462-
} else {
463-
let prefs = profile.getPreferences();
464-
if (Object.keys(prefs).length) {
465-
firefoxOptions['prefs'] = prefs;
466-
}
467-
}
468-
}
469-
470-
let sessionCaps = caps;
471-
if (caps.has(capabilities.Capability.PROXY)) {
472-
let proxy = normalizeProxyConfiguration(
473-
caps.get(capabilities.Capability.PROXY));
474-
475-
// Marionette requires proxy settings to be specified as required
476-
// capabilities. See mozilla/geckodriver#97
477-
let required = new capabilities.Capabilities()
478-
.set(capabilities.Capability.PROXY, proxy);
479-
480-
caps.delete(capabilities.Capability.PROXY);
481-
sessionCaps = {required, desired: caps};
482-
}
483-
484-
/** @type {!command.Executor} */
485-
let cmdExecutor;
486-
let onQuit = function() {};
487-
488-
if (executor instanceof http.Executor) {
489-
configureExecutor(executor);
490-
cmdExecutor = executor;
491-
} else if (executor instanceof remote.DriverService) {
492-
cmdExecutor = createExecutor(executor.start());
493-
onQuit = () => executor.kill();
494-
} else {
495-
let builder = new ServiceBuilder();
496-
if (binary) {
497-
builder.setFirefoxBinary(binary);
498-
}
499-
let service = builder.build();
500-
cmdExecutor = createExecutor(service.start());
501-
onQuit = () => service.kill();
502-
}
503-
504-
return {
505-
executor: cmdExecutor,
506-
capabilities: sessionCaps,
507-
onQuit
508-
};
509407
}
510408

511409

@@ -546,21 +444,29 @@ class Driver extends webdriver.WebDriver {
546444
caps = new capabilities.Capabilities(opt_config);
547445
}
548446

549-
let binary = caps.get(Capability.BINARY) || new Binary();
550-
caps.delete(Capability.BINARY);
551-
if (typeof binary === 'string') {
552-
binary = new Binary(binary);
447+
if (caps.has(capabilities.Capability.PROXY)) {
448+
let proxy =
449+
normalizeProxyConfiguration(caps.get(capabilities.Capability.PROXY));
450+
caps.set(capabilities.Capability.PROXY, proxy);
553451
}
554452

555-
let profile;
556-
if (caps.has(Capability.PROFILE)) {
557-
profile = caps.get(Capability.PROFILE);
558-
caps.delete(Capability.PROFILE);
453+
let executor;
454+
let onQuit;
455+
456+
if (opt_executor instanceof http.Executor) {
457+
executor = opt_executor;
458+
configureExecutor(executor);
459+
} else if (opt_executor instanceof remote.DriverService) {
460+
executor = createExecutor(opt_executor.start());
461+
onQuit = () => opt_executor.kill();
462+
} else {
463+
let service = new ServiceBuilder().build();
464+
executor = createExecutor(service.start());
465+
onQuit = () => service.kill();
559466
}
560467

561-
let spec = createGeckoDriver(opt_executor, caps, profile, binary);
562468
return /** @type {!Driver} */(super.createSession(
563-
spec.executor, spec.capabilities, opt_flow, spec.onQuit));
469+
executor, caps, opt_flow, onQuit));
564470
}
565471

566472
/**

javascript/node/selenium-webdriver/test/firefox/firefox_test.js

-19
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,6 @@ test.suite(function(env) {
171171
});
172172
});
173173

174-
test.it('can be used alongside preset capabilities', function*() {
175-
let binary = yield firefox.Channel.AURORA.locate();
176-
177-
let profile = profileWithExtensions(JETPACK_EXTENSION);
178-
profile.setPreference('general.useragent.override', 'foo;bar');
179-
180-
driver = yield env.builder()
181-
.withCapabilities({'moz:firefoxOptions': {binary}})
182-
.setFirefoxOptions(new firefox.Options().setProfile(profile))
183-
.build();
184-
185-
yield loadJetpackPage(driver,
186-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
187-
188-
let text =
189-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
190-
assert(text).equalTo('Hello, world!');
191-
});
192-
193174
function loadJetpackPage(driver, url) {
194175
// On linux the jetpack extension does not always run the first time
195176
// we load a page. If this happens, just reload the page (a simple

0 commit comments

Comments
 (0)