Skip to content

Commit

Permalink
[js] Instead of always writing to a file in the current working direc…
Browse files Browse the repository at this point in the history
…tory,

which may not be writable, add a parameter to the phantomjs.Driver
constructor to configure the path to the desired log file.

Still todo: add an Options class so phantomjs configuration is
consistent with the other drivers.

Fixes #1244
  • Loading branch information
jleyba committed Mar 11, 2016
1 parent cc27bb1 commit daf0539
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 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 @@ -23,6 +23,9 @@
module to break a circular dependency.
* FIXED: `io.findInPath()` will no longer match against directories that have
the same basename as the target file.
* FIXED: `phantomjs.Driver` now takes a third argument that defines the path to
a log file to use for the phantomjs executable's output. This may be quickly
set at runtime with the `SELENIUM_PHANTOMJS_LOG` environment variable.

### Changes for W3C WebDriver Spec Compliance

Expand Down
22 changes: 12 additions & 10 deletions javascript/node/selenium-webdriver/phantomjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ const BINARY_PATH_CAPABILITY = 'phantomjs.binary.path';
const CLI_ARGS_CAPABILITY = 'phantomjs.cli.args';


/**
* Default log file to use if one is not specified through CLI args.
* @type {string}
* @const
*/
const DEFAULT_LOG_FILE = 'phantomjsdriver.log';


/**
* Custom command names supported by PhantomJS.
* @enum {string}
Expand Down Expand Up @@ -136,11 +128,16 @@ class Driver extends webdriver.WebDriver {
* capabilities.
* @param {promise.ControlFlow=} opt_flow The control flow to use,
* or {@code null} to use the currently active flow.
* @param {string=} opt_logFile Path to the log file for the phantomjs
* executable's output. For convenience, this may be set at runtime with
* the `SELENIUM_PHANTOMJS_LOG` environment variable.
*/
constructor(opt_capabilities, opt_flow) {
constructor(opt_capabilities, opt_flow, opt_logFile) {
// TODO: add an Options class for consistency with the other driver types.

var caps = opt_capabilities || capabilities.Capabilities.phantomjs();
var exe = findExecutable(caps.get(BINARY_PATH_CAPABILITY));
var args = ['--webdriver-logfile=' + DEFAULT_LOG_FILE];
var args = [];

var logPrefs = caps.get(capabilities.Capability.LOGGING_PREFS);
if (logPrefs instanceof logging.Preferences) {
Expand All @@ -155,6 +152,11 @@ class Driver extends webdriver.WebDriver {
}
}

opt_logFile = process.env['SELENIUM_PHANTOMJS_LOG'] || opt_logFile;
if (typeof opt_logFile === 'string') {
args.push('--webdriver-logfile=' + opt_logFile);
}

var proxy = caps.get(capabilities.Capability.PROXY);
if (proxy) {
switch (proxy.proxyType) {
Expand Down

0 comments on commit daf0539

Please sign in to comment.