Skip to content

Commit

Permalink
[js] Remove the firefox.Binary class.
Browse files Browse the repository at this point in the history
This is more cleanup from removing support for the legacy FirefoxDriver. The
only functionality it still provided was the ability to specify the path to a
specific binary and define additional command line arguments for when starting
Firefox. Both of these options can be configured using the firefox.Options
class.
  • Loading branch information
jleyba committed Oct 9, 2017
1 parent d22fc51 commit f9b221f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 243 deletions.
3 changes: 3 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ mode.
- `lib/webdriver.WebElementPromise`
* The `testing/index` module no longer wraps the promise manager
* Removed `remote/index.DriverService.prototype.stop()` (use `#kill()` instead)
* Removed the `firefox.Binary` class. Custom binaries can still be selected
using `firefox.Options#setBinary()`. Likewise, custom binary arguments can be
specified with `firefox.Options#addArguments()`.
* Removed the `lib/actions` module
* Removed the `phantomjs` module
* Removed the 'opera' module
Expand Down
196 changes: 3 additions & 193 deletions javascript/node/selenium-webdriver/firefox/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,10 @@

'use strict';

const child = require('child_process'),
fs = require('fs'),
path = require('path'),
util = require('util');
const path = require('path');

const isDevMode = require('../lib/devmode'),
Symbols = require('../lib/symbols'),
io = require('../io'),
exec = require('../io/exec');



/** @const */
const NO_FOCUS_LIB_X86 = isDevMode ?
path.join(__dirname, '../../../../cpp/prebuilt/i386/libnoblur.so') :
path.join(__dirname, '../lib/firefox/i386/libnoblur.so') ;

/** @const */
const NO_FOCUS_LIB_AMD64 = isDevMode ?
path.join(__dirname, '../../../../cpp/prebuilt/amd64/libnoblur64.so') :
path.join(__dirname, '../lib/firefox/amd64/libnoblur64.so') ;

const X_IGNORE_NO_FOCUS_LIB = 'x_ignore_nofocus.so';
const io = require('../io');
const exec = require('../io/exec');


/**
Expand Down Expand Up @@ -167,181 +148,10 @@ Channel.NIGHTLY = new Channel(
'Nightly\\firefox.exe');


/**
* Copies the no focus libs into the given profile directory.
* @param {string} profileDir Path to the profile directory to install into.
* @return {!Promise<string>} The LD_LIBRARY_PATH prefix string to use
* for the installed libs.
*/
function installNoFocusLibs(profileDir) {
var x86 = path.join(profileDir, 'x86');
var amd64 = path.join(profileDir, 'amd64');

return io.mkdir(x86)
.then(() => copyLib(NO_FOCUS_LIB_X86, x86))
.then(() => io.mkdir(amd64))
.then(() => copyLib(NO_FOCUS_LIB_AMD64, amd64))
.then(function() {
return x86 + ':' + amd64;
});

function copyLib(src, dir) {
return io.copy(src, path.join(dir, X_IGNORE_NO_FOCUS_LIB));
}
}


/**
* Provides a mechanism to configure and launch Firefox in a subprocess for
* use with WebDriver.
*
* If created _without_ a path for the Firefox binary to use, this class will
* attempt to find Firefox when {@link #launch()} is called. For MacOS and
* Windows, this class will look for Firefox in the current platform's default
* installation location (e.g. /Applications/Firefox.app on MacOS). For all
* other platforms, the Firefox executable must be available on your system
* `PATH`.
*
* @final
* @deprecated This class will be removed in 4.0. Use the binary management
* functions available on the {@link ./index.Options firefox.Options} class.
*/
class Binary {
/**
* @param {?(string|Channel)=} opt_exeOrChannel Either the path to a specific
* Firefox binary to use, or a {@link Channel} instance that describes
* how to locate the desired Firefox version.
*/
constructor(opt_exeOrChannel) {
/** @private {?(string|Channel)} */
this.exe_ = opt_exeOrChannel || null;

/** @private {!Array.<string>} */
this.args_ = [];

/** @private {!Object<string, string>} */
this.env_ = {};
Object.assign(this.env_, process.env, {
MOZ_CRASHREPORTER_DISABLE: '1',
MOZ_NO_REMOTE: '1',
NO_EM_RESTART: '1'
});

/** @private {boolean} */
this.devEdition_ = false;
}

/**
* @return {(string|undefined)} The path to the Firefox executable to use, or
* `undefined` if WebDriver should attempt to locate Firefox automatically
* on the current system.
*/
getExe() {
return typeof this.exe_ === 'string' ? this.exe_ : undefined;
}

/**
* Add arguments to the command line used to start Firefox.
* @param {...(string|!Array.<string>)} var_args Either the arguments to add
* as varargs, or the arguments as an array.
* @deprecated Use {@link ./index.Options#addArguments}.
*/
addArguments(var_args) {
for (var i = 0; i < arguments.length; i++) {
if (Array.isArray(arguments[i])) {
this.args_ = this.args_.concat(arguments[i]);
} else {
this.args_.push(arguments[i]);
}
}
}

/**
* @return {!Array<string>} The command line arguments to use when starting
* the browser.
*/
getArguments() {
return this.args_;
}

/**
* Specifies whether to use Firefox Developer Edition instead of the normal
* stable channel. Setting this option has no effect if this instance was
* created with a path to a specific Firefox binary.
*
* This method has no effect on Unix systems where the Firefox application
* has the same (default) name regardless of version.
*
* @param {boolean=} opt_use Whether to use the developer edition. Defaults to
* true.
* @deprecated Use the {@link Channel} class to indicate the desired Firefox
* version when creating a new binary: `new Binary(Channel.AURORA)`.
*/
useDevEdition(opt_use) {
this.devEdition_ = opt_use === undefined || !!opt_use;
}

/**
* Returns a promise for the Firefox executable used by this instance. The
* returned promise will be immediately resolved if the user supplied an
* executable path when this instance was created. Otherwise, an attempt will
* be made to find Firefox on the current system.
*
* @return {!Promise<string>} a promise for the path to the Firefox executable
* used by this instance.
*/
locate() {
if (typeof this.exe_ === 'string') {
return Promise.resolve(this.exe_);
} else if (this.exe_ instanceof Channel) {
return this.exe_.locate();
}
let channel = this.devEdition_ ? Channel.AURORA : Channel.RELEASE;
return channel.locate();
}

/**
* Launches Firefox and returns a promise that will be fulfilled when the
* process terminates.
* @param {string} profile Path to the profile directory to use.
* @return {!Promise<!exec.Command>} A promise for the handle to the started
* subprocess.
*/
launch(profile) {
let env = {};
Object.assign(env, this.env_, {XRE_PROFILE_PATH: profile});

let args = ['-foreground'].concat(this.args_);

return this.locate().then(function(firefox) {
if (process.platform === 'win32' || process.platform === 'darwin') {
return exec(firefox, {args: args, env: env});
}
return installNoFocusLibs(profile).then(function(ldLibraryPath) {
env['LD_LIBRARY_PATH'] = ldLibraryPath + ':' + env['LD_LIBRARY_PATH'];
env['LD_PRELOAD'] = X_IGNORE_NO_FOCUS_LIB;
return exec(firefox, {args: args, env: env});
});
});
}

/**
* Returns a promise for the wire representation of this binary. Note: the
* FirefoxDriver only supports passing the path to the binary executable over
* the wire; all command line arguments and environment variables will be
* discarded.
*
* @return {!Promise<string>} A promise for this binary's wire representation.
*/
[Symbols.serialize]() {
return this.locate();
}
}


// PUBLIC API


exports.Binary = Binary;
exports.Channel = Channel;

34 changes: 7 additions & 27 deletions javascript/node/selenium-webdriver/firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

const url = require('url');

const {Binary, Channel} = require('./binary'),
const {Channel} = require('./binary'),
Profile = require('./profile').Profile,
http = require('../http'),
httpUtil = require('../http/util'),
Expand All @@ -144,7 +144,7 @@ class Options {
/** @private {Profile} */
this.profile_ = null;

/** @private {(Binary|Channel|string|null)} */
/** @private {(Channel|string|null)} */
this.binary_ = null;

/** @private {!Array<string>} */
Expand Down Expand Up @@ -216,22 +216,18 @@ class Options {

/**
* Sets the binary to use. The binary may be specified as the path to a
* Firefox executable, a specific {@link Channel}, or as a {@link Binary}
* object.
* Firefox executable or a desired release {@link Channel}.
*
* @param {(string|!Binary|!Channel)} binary The binary to use.
* @param {(string|!Channel)} binary The binary to use.
* @return {!Options} A self reference.
* @throws {TypeError} If `binary` is an invalid type.
*/
setBinary(binary) {
if (binary instanceof Binary
|| binary instanceof Channel
|| typeof binary === 'string') {
if (binary instanceof Channel || typeof binary === 'string') {
this.binary_ = binary;
return this;
}
throw TypeError(
'binary must be a string path, Channel, or Binary object');
throw TypeError('binary must be a string path or Channel object');
}

/**
Expand Down Expand Up @@ -278,22 +274,7 @@ class Options {
}

if (this.binary_) {
if (this.binary_ instanceof Binary) {
let exe = this.binary_.getExe();
if (exe) {
firefoxOptions['binary'] = exe;
}

let args = this.binary_.getArguments();
if (args.length) {
if (this.args_.length) {
throw Error(
'You may specify browser arguments with Options.addArguments'
+ ' (preferred) or Binary.addArguments, but not both');
}
firefoxOptions['args'] = args;
}
} else if (this.binary_ instanceof Channel) {
if (this.binary_ instanceof Channel) {
firefoxOptions['binary'] = this.binary_.locate();

} else if (typeof this.binary_ === 'string') {
Expand Down Expand Up @@ -560,7 +541,6 @@ class Driver extends webdriver.WebDriver {
// PUBLIC API


exports.Binary = Binary;
exports.Channel = Channel;
exports.Context = Context;
exports.Driver = Driver;
Expand Down
23 changes: 0 additions & 23 deletions javascript/node/selenium-webdriver/test/firefox/firefox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,29 +181,6 @@ suite(function(env) {
}
});

describe('binary management', function() {
var driver1, driver2;

ignore(env.isRemote).
it('can start multiple sessions with single binary instance', async function() {
var options = new firefox.Options().setBinary(new firefox.Binary);
env.builder().setFirefoxOptions(options);
driver1 = await env.builder().build();
driver2 = await env.builder().build();
// Ok if this doesn't fail.
});

afterEach(async function() {
if (driver1) {
await driver1.quit();
}

if (driver2) {
await driver2.quit();
}
});
});

describe('context switching', function() {
var driver;

Expand Down

0 comments on commit f9b221f

Please sign in to comment.