From de859b5543ea4961a3141a33a07e9a4de3e3cb70 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Wed, 2 May 2018 15:23:20 +0300 Subject: [PATCH 01/15] Added usage info to readme. Now it can be imported as a module --- README.md | 33 +++++++++++++++++++++++++++++++-- index.js | 23 +++++++++++++++-------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c3842c3..87ca131 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,33 @@ -[![Build Status](https://travis-ci.org/cdagli/browser-driver-installer.svg?branch=master)](https://travis-ci.org/cdagli/browser-driver-installer) +[![Build Status](https://travis-ci.org/unscrambl/browser-driver-installer.svg?branch=master)](https://travis-ci.org/unscrambl/browser-driver-installer) # browser-driver-installer -Installs Chrome and Gecko drivers that match with the specified browser versions +Installs Chrome and Gecko drivers that match with the specified browser versions. + +#### Usage: + +**Post Install Script:** If your environment has the `CHROME_VERSION`, `CHROMEDRIVER_PATH`, `FIREFOX_VERSION`, `GECKODRIVER_PATH` variables defined, a post-install script will download the `ChromeDriver` and `GeckoDriver` executables to the specified paths automatically. + + +**As a module:** +``` +const driverInstaller = require('browser-driver-installer').driverInstaller; +driverInstaller(CHROME_VERSION, CHROMEDRIVER_TARGET_PATH, FIREFOX_VERSION, GECKODRIVER_TARGET_PATH); +``` + + +**CLI Usage:** + +```` +Usage: index [options] + + Options: + + --chrome-version [chromeVersion] Chrome browser major version string e.g. 65 + --chrome-driver-target-path [chromeDriverTargetPath] Path to install Chrome driver executable + --firefox-version [firefoxVersion] Firefox browser major version string e.g. 57 + --firefox-driver-target-path [firefoxDriverTargetPath] Path to install Firefox driver(geckoDriver) executable + -h, --help output usage information +```` + +## LICENSE +[Apache 2.0](https://github.com/unscrambl/browser-driver-installer/blob/master/LICENSE) \ No newline at end of file diff --git a/index.js b/index.js index 60923e4..d01d7ff 100644 --- a/index.js +++ b/index.js @@ -3,12 +3,19 @@ const program = require('commander'); const driverInstaller = require('./installer').driverInstaller; -program - .option('--chrome-version [chromeVersion]', 'Chrome browser major version string e.g. 65') - .option('--chrome-driver-target-path [chromeDriverTargetPath]', 'Path to install Chrome driver executable') - .option('--firefox-version [firefoxVersion]', 'Firefox browser major version string e.g. 57') - .option('--firefox-driver-target-path [firefoxDriverTargetPath]', - 'Path to install Firefox driver(geckoDriver) executable') - .parse(process.argv); +if (require.main === module) +{ + program + .option('--chrome-version [chromeVersion]', 'Chrome browser major version string e.g. 65') + .option('--chrome-driver-target-path [chromeDriverTargetPath]', 'Path to install Chrome driver executable') + .option('--firefox-version [firefoxVersion]', 'Firefox browser major version string e.g. 57') + .option('--firefox-driver-target-path [firefoxDriverTargetPath]', + 'Path to install Firefox driver(geckoDriver) executable') + .parse(process.argv); -driverInstaller(program.chromeVersion, program.chromeDriverTargetPath, program.firefoxVersion, program.firefoxDriverTargetPath); \ No newline at end of file + driverInstaller(program.chromeVersion, program.chromeDriverTargetPath, program.firefoxVersion, program.firefoxDriverTargetPath); +} +else +{ + module.exports.driverInstaller = driverInstaller; +} \ No newline at end of file From f57ee000be209b48ec15d0d5da789b95723a459c Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Wed, 2 May 2018 15:27:21 +0300 Subject: [PATCH 02/15] Updated README to include driver NPM package links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 87ca131..a9fa5f9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Build Status](https://travis-ci.org/unscrambl/browser-driver-installer.svg?branch=master)](https://travis-ci.org/unscrambl/browser-driver-installer) # browser-driver-installer -Installs Chrome and Gecko drivers that match with the specified browser versions. +Installs Chrome and Gecko drivers that match with the specified browser versions. It uses the [chromedriver](https://www.npmjs.com/package/chromedriver) and [geckodriver](https://www.npmjs.com/package/geckodriver) NPM packages to download the drivers. #### Usage: From 6eb08f8d2d32c4a7ae3034ecc14ed7373efcbb97 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Wed, 2 May 2018 15:28:46 +0300 Subject: [PATCH 03/15] Updated the env variable names to be more specific --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a9fa5f9..1e144da 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Installs Chrome and Gecko drivers that match with the specified browser versions #### Usage: -**Post Install Script:** If your environment has the `CHROME_VERSION`, `CHROMEDRIVER_PATH`, `FIREFOX_VERSION`, `GECKODRIVER_PATH` variables defined, a post-install script will download the `ChromeDriver` and `GeckoDriver` executables to the specified paths automatically. +**Post Install Script:** If your environment has the `BROWSER_DRIVER_INSTALLER_CHROME_VERSION`, `BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH`, `BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION`, `BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH` variables defined, a post-install script will download the `ChromeDriver` and `GeckoDriver` executables to the specified paths automatically. **As a module:** diff --git a/package.json b/package.json index 3c36ddb..19d9c1b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "main": "index.js", "name": "browser-driver-installer", "scripts": { - "postinstall": "node ./index.js --chrome-version $CHROME_VERSION --chrome-driver-target-path $CHROMEDRIVER_PATH --firefox-version $FIREFOX_VERSION --firefox-driver-target-path $GECKODRIVER_PATH", + "postinstall": "node ./index.js --chrome-version $BROWSER_DRIVER_INSTALLER_CHROME_VERSION --chrome-driver-target-path $BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH --firefox-version $BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION --firefox-driver-target-path $BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH", "test": "node_modules/mocha/bin/mocha *.spec.js" }, "version": "0.0.1" From 04e7b14c4771d9d323ac7b06dd8a07f3ce8a9ab2 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 09:58:34 +0300 Subject: [PATCH 04/15] Separated the installation scripts. One driver at a time --- index.js | 10 +++--- installer.js | 86 ++++++++++++++++++++++------------------------- installer.spec.js | 5 ++- package.json | 7 ++-- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/index.js b/index.js index d01d7ff..3851138 100644 --- a/index.js +++ b/index.js @@ -6,14 +6,12 @@ const driverInstaller = require('./installer').driverInstaller; if (require.main === module) { program - .option('--chrome-version [chromeVersion]', 'Chrome browser major version string e.g. 65') - .option('--chrome-driver-target-path [chromeDriverTargetPath]', 'Path to install Chrome driver executable') - .option('--firefox-version [firefoxVersion]', 'Firefox browser major version string e.g. 57') - .option('--firefox-driver-target-path [firefoxDriverTargetPath]', - 'Path to install Firefox driver(geckoDriver) executable') + .option('--browser-name ', 'Browser to install the driver for') + .option('--browser-version ', 'Browser version string e.g. 65, 67.0.23') + .option('--target-path ', 'Path to install driver executable') .parse(process.argv); - driverInstaller(program.chromeVersion, program.chromeDriverTargetPath, program.firefoxVersion, program.firefoxDriverTargetPath); + driverInstaller(program.browserName, program.browserVersion, program.targetPath); } else { diff --git a/installer.js b/installer.js index c367105..ca2e9c2 100644 --- a/installer.js +++ b/installer.js @@ -6,18 +6,21 @@ const path = require('path'); const execSync = require('child_process').execSync; const shell = require('shelljs'); -const TEMP_DIR = 'temp'; +const BROWSER_MAJOR_VERSION_REGEX = new RegExp(/^(\d+)/); +const CHROME_BROWSER_NAME = 'chrome'; const CHROME_DRIVER_NAME = 'chromedriver'; const CHROME_DRIVER_BIN_PATH = path.join('node_modules', 'chromedriver', 'lib', 'chromedriver', CHROME_DRIVER_NAME); const CHROME_DRIVER_VERSION_REGEX = new RegExp(/\w+ ([0-9]+.[0-9]+).+/); const GECKO_DRIVER_NAME = 'geckodriver'; const GECKO_DRIVER_BIN_PATH = path.join('node_modules', 'geckodriver', GECKO_DRIVER_NAME); const GECKO_DRIVER_VERSION_REGEX = new RegExp(/\w+\s(\d+.\d+.\d+)/); -const BROWSER_MAJOR_VERSION_REGEX = new RegExp(/^(\d+)/); +const FIREFOX_BROWSER_NAME = 'firefox'; +const TEMP_DIR = 'temp'; +const VALID_BROWSER_NAMES = [CHROME_BROWSER_NAME, FIREFOX_BROWSER_NAME]; -function installDriverWithVersion(driverName, driverBinPath, installPath, versionObject) +function installDriverWithVersion(driverName, driverBinPath, targetPath, versionObject) { - if (checkDirectoryAndVersion(driverName, installPath, versionObject.driverVersion)) + if (checkDirectoryAndVersion(driverName, targetPath, versionObject.driverVersion)) { return false; } @@ -29,8 +32,8 @@ function installDriverWithVersion(driverName, driverBinPath, installPath, versio ]).then( function () { - shell.mkdir('-p', installPath); - shell.cp('-n', path.join(TEMP_DIR, driverBinPath), installPath); + shell.mkdir('-p', targetPath); + shell.cp('-n', path.join(TEMP_DIR, driverBinPath), targetPath); shell.rm('-rf', TEMP_DIR); console.log('package dependencies have been installed'); return true; @@ -41,30 +44,30 @@ function installDriverWithVersion(driverName, driverBinPath, installPath, versio }); } -function checkDirectoryAndVersion(driverName, installPath, driverExpectedVersion) +function checkDirectoryAndVersion(driverName, targetPath, driverExpectedVersion) { - if (!shell.test('-e', installPath)) + if (!shell.test('-e', targetPath)) { return false; } - console.log(`Directory '${installPath}' does exist.`); + console.log(`Directory '${targetPath}' does exist.`); console.log(`Checking if the directory contains a ${driverName}...`); - if (!shell.test('-e', path.join(installPath, driverName))) + if (!shell.test('-e', path.join(targetPath, driverName))) { - console.log(`Could not find the ${driverName} in the directory '${installPath}'. Attempting to install it...`); + console.log(`Could not find the ${driverName} in the directory '${targetPath}'. Attempting to install it...`); return false; } console.log(`${driverName} found.`); - const driverMajorVersion = driverVersionString(driverName, installPath); + const driverMajorVersion = driverVersionString(driverName, targetPath); if (driverMajorVersion !== driverExpectedVersion) { console.log( `${driverName} expected version (${driverExpectedVersion}) does not match with the installed version (${driverMajorVersion}).` ); console.log('Removing the old version...'); - shell.rm(path.join(installPath, driverName)); + shell.rm(path.join(targetPath, driverName)); return false; } @@ -72,17 +75,17 @@ function checkDirectoryAndVersion(driverName, installPath, driverExpectedVersion return true; } -function driverVersionString(driverName, installPath) +function driverVersionString(driverName, targetPath) { let versionOutput = null; if (driverName === CHROME_DRIVER_NAME) { - versionOutput = execSync(path.join(installPath, driverName) + ' -v').toString(); + versionOutput = execSync(path.join(targetPath, driverName) + ' -v').toString(); return versionOutput.match(CHROME_DRIVER_VERSION_REGEX)[1]; } else if (driverName === GECKO_DRIVER_NAME) { - versionOutput = execSync(path.join(installPath, driverName) + ' -V').toString(); + versionOutput = execSync(path.join(targetPath, driverName) + ' -V').toString(); return versionOutput.match(GECKO_DRIVER_VERSION_REGEX)[1]; } else @@ -91,52 +94,45 @@ function driverVersionString(driverName, installPath) } } -function driverInstaller(detectedChromeVersion, chromeDriverTargetPath, detectedFirefoxVersion, geckoDriverTargetPath) +function driverInstaller(browserName, browserVersion, targetPath) { - const browserVersionsObject = JSON.parse(shell.cat(path.resolve(__dirname, 'driverVersions.json'))); - // ChromeDriver NPM package versions are defined according to https://github.com/giggio/node-chromedriver/releases - const chromeDriverVersions = browserVersionsObject.chromeDriverVersions; - // GeckoDriver NPM package versions are defined according to https://github.com/mozilla/geckodriver/releases - const geckoDriverVersions = browserVersionsObject.geckoDriverVersions; + // ChromeDriver NPM package versions are defined according to https://github.com/giggio/node-chromedriver/releases + const browserVersionsObject = JSON.parse(shell.cat(path.resolve(__dirname, 'driverVersions.json'))); - detectedChromeVersion = majorBrowserVersion(detectedChromeVersion); - detectedFirefoxVersion = majorBrowserVersion(detectedFirefoxVersion); + let browserDriverVersions = null; + let driverBinPath = null; + let driverName = null; - if (detectedChromeVersion && !chromeDriverVersions[detectedChromeVersion]) + if (browserName.toLowerCase() === CHROME_BROWSER_NAME) { - throw new Error( - `Failed to locate a version of ChromeDriver that matches the installed version of Chrome (${detectedChromeVersion}). Valid Chrome versions are: ${Object.keys(chromeDriverVersions).join(', ')}` - ); + browserDriverVersions = browserVersionsObject.chromeDriverVersions; + driverBinPath = CHROME_DRIVER_BIN_PATH; + driverName = CHROME_DRIVER_NAME; } - else if (detectedChromeVersion && typeof (chromeDriverTargetPath) === 'string') + else if (browserName.toLowerCase() === FIREFOX_BROWSER_NAME) { - return installDriverWithVersion(CHROME_DRIVER_NAME, CHROME_DRIVER_BIN_PATH, chromeDriverTargetPath, - chromeDriverVersions[detectedChromeVersion]); + browserDriverVersions = browserVersionsObject.geckoDriverVersions; + driverBinPath = GECKO_DRIVER_BIN_PATH; + driverName = GECKO_DRIVER_NAME; } else { - console.log('No Chrome version or target path is provided. Skipping...'); + throw new Error( + `Browser name "${browserName}" is not a valid browser name. Valid browser names are: ${(VALID_BROWSER_NAMES).join(', ')}` + ); } - if (detectedFirefoxVersion && !geckoDriverVersions[detectedFirefoxVersion]) + browserVersion = majorBrowserVersion(browserVersion); + + if (browserVersion && !browserDriverVersions[browserVersion]) { throw new Error( - `Failed to locate a version of GeckoDriver that matches the installed version of Firefox (${detectedFirefoxVersion}). Valid Firefox versions are: ${Object.keys(geckoDriverVersions).join(', ')}` + `Failed to locate a version of ${driverName} that matches the installed version of ${browserName} (${browserVersion}). Valid ${browserName} versions are: ${Object.keys(browserDriverVersions).join(', ')}` ); } - else if (detectedFirefoxVersion && (typeof geckoDriverTargetPath) === 'string') - { - return installDriverWithVersion(GECKO_DRIVER_NAME, GECKO_DRIVER_BIN_PATH, geckoDriverTargetPath, - geckoDriverVersions[ - detectedFirefoxVersion]); - } - else - { - console.log('No Firefox version or target path is provided. Skipping...'); - } - return false; + return installDriverWithVersion(driverName, driverBinPath, targetPath, browserDriverVersions[browserVersion]); } function majorBrowserVersion(browserVersionString) diff --git a/installer.spec.js b/installer.spec.js index 5f51608..22bf8d0 100644 --- a/installer.spec.js +++ b/installer.spec.js @@ -1,3 +1,6 @@ +'use strict'; +/* eslint-disable no-console */ + const chai = require('chai'); const installer = require('./installer'); const expect = require('chai').expect; @@ -34,7 +37,7 @@ describe('browserDriverInstaller', function () it('should not attempt to install anything if one of the path, version or both parameters are not provided', function () { - expect(installer.driverInstaller()).to.be.false; + // expect(installer.driverInstaller()).to.be.false; expect(console.log).to.have.been.calledWith( 'No Chrome version or target path is provided. Skipping...'); expect(console.log).to.have.been.calledWith( diff --git a/package.json b/package.json index 19d9c1b..81cb312 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,12 @@ "license": "Apache-2.0", "main": "index.js", "name": "browser-driver-installer", + "repository": "github:unscrambl/browser-driver-installer", "scripts": { - "postinstall": "node ./index.js --chrome-version $BROWSER_DRIVER_INSTALLER_CHROME_VERSION --chrome-driver-target-path $BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH --firefox-version $BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION --firefox-driver-target-path $BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH", + "install-chromedriver": "node ./index.js --browser-name chrome --browser-version $BROWSER_DRIVER_INSTALLER_CHROME_VERSION --target-path $BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH", + "install-geckodriver": "node ./index.js --browser-name firefox --browser-version $BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION --target-path $BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH", + "postinstall": "install-chromedriver && install-geckodriver", "test": "node_modules/mocha/bin/mocha *.spec.js" }, - "version": "0.0.1" + "version": "1.0.1" } From c7922be1bda7eea8f3ed6d6338cb8aaa4608f4e4 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:07:45 +0300 Subject: [PATCH 05/15] Added string check to the installer script --- installer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/installer.js b/installer.js index ca2e9c2..e0628df 100644 --- a/installer.js +++ b/installer.js @@ -96,6 +96,10 @@ function driverVersionString(driverName, targetPath) function driverInstaller(browserName, browserVersion, targetPath) { + if (typeof browserName !== 'string' || typeof browserVersion !== 'string' || typeof targetPath !== 'string') + { + throw new Error('Parameters are not valid strings.'); + } // GeckoDriver NPM package versions are defined according to https://github.com/mozilla/geckodriver/releases // ChromeDriver NPM package versions are defined according to https://github.com/giggio/node-chromedriver/releases const browserVersionsObject = JSON.parse(shell.cat(path.resolve(__dirname, 'driverVersions.json'))); From 0cadbb4eeeaf8455fac0f9ab09fabfa24968e142 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:24:56 +0300 Subject: [PATCH 06/15] Updated and fixed tests --- installer.spec.js | 20 +++++++++----------- package.json | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/installer.spec.js b/installer.spec.js index 22bf8d0..3301666 100644 --- a/installer.spec.js +++ b/installer.spec.js @@ -37,25 +37,23 @@ describe('browserDriverInstaller', function () it('should not attempt to install anything if one of the path, version or both parameters are not provided', function () { - // expect(installer.driverInstaller()).to.be.false; - expect(console.log).to.have.been.calledWith( - 'No Chrome version or target path is provided. Skipping...'); - expect(console.log).to.have.been.calledWith( - 'No Firefox version or target path is provided. Skipping...'); + expect(function () { installer.driverInstaller(); }).to.throw( + 'Parameters are not valid strings.'); }); it('should throw an error if the provided version does not included in the JSON file', function () { const wrongVersionNumber = '1'; - expect(function () { installer.driverInstaller(wrongVersionNumber, '/some/target/path'); }).to.throw( - /Failed to locate a version of ChromeDriver that matches the installed version of Chrome \(1\). Valid Chrome versions are:*/ + expect(function () { installer.driverInstaller('chrome', wrongVersionNumber, + '/some/target/path'); }).to.throw( + /Failed to locate a version of chromedriver that matches the installed version of chrome \(1\). Valid chrome versions are:*/ ); }); it('should install the chromedriver to specified path if the version is included in the JSON file', function () { - return installer.driverInstaller('54', DRIVER_OUTPUT_PATH).then(function () + return installer.driverInstaller('chrome', '54', DRIVER_OUTPUT_PATH).then(function () { expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'chromedriver'))).to.be.true; }); @@ -63,7 +61,7 @@ describe('browserDriverInstaller', function () it('should install the geckodriver to specified path if the version is included in the JSON file', function () { - return installer.driverInstaller(null, null, '55', DRIVER_OUTPUT_PATH).then(function () + return installer.driverInstaller('firefox', '55', DRIVER_OUTPUT_PATH).then(function () { expect(shell.test('-e', path.resolve(DRIVER_OUTPUT_PATH, 'geckodriver'))).to.be.true; }); @@ -71,9 +69,9 @@ describe('browserDriverInstaller', function () it('should not install again if the wanted version is already installed', function () { - return installer.driverInstaller('54', DRIVER_OUTPUT_PATH).then(function () + return installer.driverInstaller('chrome', '54', DRIVER_OUTPUT_PATH).then(function () { - expect(installer.driverInstaller('54', DRIVER_OUTPUT_PATH)).to.be.false; + expect(installer.driverInstaller('chrome', '54', DRIVER_OUTPUT_PATH)).to.be.false; }); }); }); \ No newline at end of file diff --git a/package.json b/package.json index 81cb312..7574b61 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "scripts": { "install-chromedriver": "node ./index.js --browser-name chrome --browser-version $BROWSER_DRIVER_INSTALLER_CHROME_VERSION --target-path $BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH", "install-geckodriver": "node ./index.js --browser-name firefox --browser-version $BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION --target-path $BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH", - "postinstall": "install-chromedriver && install-geckodriver", + "postinstall": "npm run install-chromedriver && npm run install-geckodriver", "test": "node_modules/mocha/bin/mocha *.spec.js" }, "version": "1.0.1" From cc0e32b3a8ffdd425fe2971a19d139af5bcd0ace Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:27:31 +0300 Subject: [PATCH 07/15] Updated the README --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1e144da..1ad3f98 100644 --- a/README.md +++ b/README.md @@ -11,22 +11,21 @@ Installs Chrome and Gecko drivers that match with the specified browser versions **As a module:** ``` const driverInstaller = require('browser-driver-installer').driverInstaller; -driverInstaller(CHROME_VERSION, CHROMEDRIVER_TARGET_PATH, FIREFOX_VERSION, GECKODRIVER_TARGET_PATH); +driverInstaller(BROWSER_NAME, BROWSER_VERSION, TARGET_PATH); ``` **CLI Usage:** ```` -Usage: index [options] + Usage: index [options] Options: - --chrome-version [chromeVersion] Chrome browser major version string e.g. 65 - --chrome-driver-target-path [chromeDriverTargetPath] Path to install Chrome driver executable - --firefox-version [firefoxVersion] Firefox browser major version string e.g. 57 - --firefox-driver-target-path [firefoxDriverTargetPath] Path to install Firefox driver(geckoDriver) executable - -h, --help output usage information + --browser-name Browser to install the driver for + --browser-version Browser version string e.g. 65, 67.0.23 + --target-path Path to install driver executable + -h, --help output usage information ```` ## LICENSE From 95f0a1e98e5c0c3f0432b1e8159c7654479e6f8a Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:34:54 +0300 Subject: [PATCH 08/15] Added env variables for Travis CI --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9e6e4e1..3191db9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ language: node_js node_js: - - "node" \ No newline at end of file + - "node" +env: + - BROWSER_DRIVER_INSTALLER_CHROME_VERSION=67 + - BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH=/tmp + - BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION=57 + - BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH=/tmp \ No newline at end of file From a6b3dc6e0c433833d507bef5b3643f41f07256e3 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:39:15 +0300 Subject: [PATCH 09/15] Changed Travis CI env variables to global --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3191db9..f6b3079 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ language: node_js node_js: - "node" env: - - BROWSER_DRIVER_INSTALLER_CHROME_VERSION=67 - - BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH=/tmp - - BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION=57 - - BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH=/tmp \ No newline at end of file + global: + - BROWSER_DRIVER_INSTALLER_CHROME_VERSION=67 + - BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH=/tmp + - BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION=57 + - BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH=/tmp \ No newline at end of file From 7045e154a71d798f45b98cf29674f8651cf8e071 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 10:42:11 +0300 Subject: [PATCH 10/15] Bump version to 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7574b61..695e714 100644 --- a/package.json +++ b/package.json @@ -22,5 +22,5 @@ "postinstall": "npm run install-chromedriver && npm run install-geckodriver", "test": "node_modules/mocha/bin/mocha *.spec.js" }, - "version": "1.0.1" + "version": "1.0.2" } From 358ab5dd9858d06c2596e3c0fb555c2e71007f6a Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 11:28:22 +0300 Subject: [PATCH 11/15] Created a postinstall script. Bumped to version 1.0.3 --- installer.spec.js | 7 +++++-- package.json | 6 ++---- postinstall | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100755 postinstall diff --git a/installer.spec.js b/installer.spec.js index 3301666..751010f 100644 --- a/installer.spec.js +++ b/installer.spec.js @@ -44,8 +44,11 @@ describe('browserDriverInstaller', function () it('should throw an error if the provided version does not included in the JSON file', function () { const wrongVersionNumber = '1'; - expect(function () { installer.driverInstaller('chrome', wrongVersionNumber, - '/some/target/path'); }).to.throw( + expect(function () + { + installer.driverInstaller('chrome', wrongVersionNumber, + '/some/target/path'); + }).to.throw( /Failed to locate a version of chromedriver that matches the installed version of chrome \(1\). Valid chrome versions are:*/ ); }); diff --git a/package.json b/package.json index 695e714..20a13f0 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,8 @@ "name": "browser-driver-installer", "repository": "github:unscrambl/browser-driver-installer", "scripts": { - "install-chromedriver": "node ./index.js --browser-name chrome --browser-version $BROWSER_DRIVER_INSTALLER_CHROME_VERSION --target-path $BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH", - "install-geckodriver": "node ./index.js --browser-name firefox --browser-version $BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION --target-path $BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH", - "postinstall": "npm run install-chromedriver && npm run install-geckodriver", + "postinstall": "./postinstall", "test": "node_modules/mocha/bin/mocha *.spec.js" }, - "version": "1.0.2" + "version": "1.0.3" } diff --git a/postinstall b/postinstall new file mode 100755 index 0000000..dc5bd2c --- /dev/null +++ b/postinstall @@ -0,0 +1,17 @@ +#!/bin/bash + +if [[ (-n "${BROWSER_DRIVER_INSTALLER_CHROME_VERSION}") && (-n "${BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH}")]]; then + node ./index.js --browser-name chrome \ + --browser-version "$BROWSER_DRIVER_INSTALLER_CHROME_VERSION" \ + --target-path "$BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH" +else + echo "Environment variables for Chrome are not set, skipping post-install for Chrome" +fi + +if [[ (-n "${BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION}") && (-n "${BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH}")]]; then + node ./index.js --browser-name chrome \ + --browser-version "$BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION" \ + --target-path "$BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH" +else + echo "Environment variables for Firefox are not set, skipping post-install for Firefox" +fi From 14bea4a3abb583d0e185f8c32e5addd9b0886d88 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 12:32:08 +0300 Subject: [PATCH 12/15] Clear the tmp folder before installing in the TravisCI --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f6b3079..3dd07dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: - "node" +before_install: + - rm -rf /tmp/* env: global: - BROWSER_DRIVER_INSTALLER_CHROME_VERSION=67 From 7cb3da0676a062a17f7b93ea00f73922b6e1e848 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 12:38:27 +0300 Subject: [PATCH 13/15] Adjust output paths for the initial build --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3dd07dd..934e4b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: node_js node_js: - "node" -before_install: - - rm -rf /tmp/* env: global: - BROWSER_DRIVER_INSTALLER_CHROME_VERSION=67 - - BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH=/tmp + - BROWSER_DRIVER_INSTALLER_CHROMEDRIVER_PATH=./output/chromedriver - BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION=57 - - BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH=/tmp \ No newline at end of file + - BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH=./output/geckodriver \ No newline at end of file From a76643ecdd8c56c989ea68a0c33422c7217b0dc8 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 12:54:40 +0300 Subject: [PATCH 14/15] Fixed the bug in the postinstall script --- postinstall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postinstall b/postinstall index dc5bd2c..acfac3e 100755 --- a/postinstall +++ b/postinstall @@ -9,7 +9,7 @@ else fi if [[ (-n "${BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION}") && (-n "${BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH}")]]; then - node ./index.js --browser-name chrome \ + node ./index.js --browser-name firefox \ --browser-version "$BROWSER_DRIVER_INSTALLER_FIREFOX_VERSION" \ --target-path "$BROWSER_DRIVER_INSTALLER_GECKODRIVER_PATH" else From a3c4ac6ef41d165e9df0d0a1f2022abe7f406b61 Mon Sep 17 00:00:00 2001 From: Caner Dagli Date: Thu, 3 May 2018 12:56:18 +0300 Subject: [PATCH 15/15] Bump version to 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20a13f0..4e0d38f 100644 --- a/package.json +++ b/package.json @@ -20,5 +20,5 @@ "postinstall": "./postinstall", "test": "node_modules/mocha/bin/mocha *.spec.js" }, - "version": "1.0.3" + "version": "1.0.4" }