From daf0539dab967a434478d5ea8b89794343a3c552 Mon Sep 17 00:00:00 2001 From: Jason Leyba Date: Fri, 11 Mar 2016 14:55:04 -0800 Subject: [PATCH] [js] Instead of always writing to a file in the current working directory, 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 --- javascript/node/selenium-webdriver/CHANGES.md | 3 +++ .../node/selenium-webdriver/phantomjs.js | 22 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/javascript/node/selenium-webdriver/CHANGES.md b/javascript/node/selenium-webdriver/CHANGES.md index f9c36cceca869..4b8a7b2cfa4aa 100644 --- a/javascript/node/selenium-webdriver/CHANGES.md +++ b/javascript/node/selenium-webdriver/CHANGES.md @@ -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 diff --git a/javascript/node/selenium-webdriver/phantomjs.js b/javascript/node/selenium-webdriver/phantomjs.js index 7853149b3411f..d2f2aaa3e1b62 100644 --- a/javascript/node/selenium-webdriver/phantomjs.js +++ b/javascript/node/selenium-webdriver/phantomjs.js @@ -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} @@ -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) { @@ -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) {