From c0eb120b89d4bb30ce246e1b4bb8420e809a5676 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 31 Jan 2022 11:57:34 -0800 Subject: [PATCH] fix: Fix chromedriver arguments chromedriver requires very specifically "--port=..." instead of "--port ..." or "-p ...". --- index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8c1dcfb..2b67c9b 100644 --- a/index.js +++ b/index.js @@ -26,8 +26,8 @@ const PLATFORM_MAP = { 'linux': 'Linux', }; -const LocalWebDriverBase = - function(browserName, driverCommand, baseBrowserDecorator, logger) { +const LocalWebDriverBase = function( + browserName, driverCommand, argsFromPort, baseBrowserDecorator, logger) { baseBrowserDecorator(this); this.browserName = browserName; @@ -38,12 +38,17 @@ const LocalWebDriverBase = win32: driverCommand, }; + const port = Math.floor((Math.random() * 1000)) + 4000; + + // Called by the base class to get arguments to pass to the driver command. + this._getOptions = () => argsFromPort(port.toString()); + this.ENV_CMD = driverCommand.toUpperCase() + '_PATH'; const config = { protocol: 'http:', hostname: '127.0.0.1', - port: Math.floor((Math.random() * 1000)) + 4000, + port, pathname: '/' }; @@ -73,8 +78,6 @@ const LocalWebDriverBase = log.debug('[http] ' + meth + ' ' + path + ' ' + (data || '')); }); - this._getOptions = () => ['-p', config.port.toString()]; - this.on('start', (url) => { this.browser.init(this.spec, (error) => { if (error) { @@ -141,19 +144,26 @@ const LocalWebDriverBase = const LocalWebDriverChrome = function(baseBrowserDecorator, logger) { LocalWebDriverBase.call(this, - 'Chrome', 'chromedriver', baseBrowserDecorator, logger); + 'Chrome', 'chromedriver', (port) => ['--port=' + port], + baseBrowserDecorator, logger); }; +// TODO: Add Chrome on android? + const LocalWebDriverFirefox = function(baseBrowserDecorator, logger) { LocalWebDriverBase.call(this, - 'Firefox', 'geckodriver', baseBrowserDecorator, logger); + 'Firefox', 'geckodriver', (port) => ['-p', port], + baseBrowserDecorator, logger); }; const LocalWebDriverSafari = function(baseBrowserDecorator, logger) { LocalWebDriverBase.call(this, - 'Safari', 'safaridriver', baseBrowserDecorator, logger); + 'Safari', '/usr/bin/safaridriver', (port) => ['-p', port], + baseBrowserDecorator, logger); }; +// TODO: Add MS Edge + LocalWebDriverChrome.$inject = ['baseBrowserDecorator', 'logger']; LocalWebDriverFirefox.$inject = ['baseBrowserDecorator', 'logger']; LocalWebDriverSafari.$inject = ['baseBrowserDecorator', 'logger'];