diff --git a/README.md b/README.md index 09fffed..c50c2bc 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,12 @@ more details on it. > This package can work with Microsoft Edge WebDriver as well, but the support is limited. > For example, automatic downloads do not work for Microsoft Edge WebDriver. -## Skipping binary installation +## Automatic Chromedriver download on module install + +Since version 6.0.0 of this module automatic download of the latest known chromedriver +does not happen anymore. The below information is only relevant for older module versions: + +### Skipping binary installation By default, upon installation the package downloads the most recent known Chromedriver version from Chromedriver CDN server: http://chromedriver.storage.googleapis.com. @@ -35,7 +40,7 @@ binary set the `APPIUM_SKIP_CHROMEDRIVER_INSTALL` environment variable: APPIUM_SKIP_CHROMEDRIVER_INSTALL=1 npm install appium-chromedriver ``` -## Custom Chromedriver version +### Custom Chromedriver version By default, the package uses the most recent known Chromedriver version. The full list of known Chromedriver versions and their corresponding supported @@ -51,19 +56,8 @@ CHROMEDRIVER_VERSION=107.0.5304.62 npm install appium-chromedriver ## Custom binaries url If you want Chromedriver to be downloaded from another CDN, which differs from the -default one https://chromedriver.storage.googleapis.com, then either set the npm config property `chromedriver_cdnurl`: - -```bash -npm install appium-chromedriver --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver -``` - -The property could also be added into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file. - -```bash -chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver -``` - -Or set the new URL to `CHROMEDRIVER_CDNURL` environment variable: +default one https://chromedriver.storage.googleapis.com, then set the new URL to +the `CHROMEDRIVER_CDNURL` environment variable: ```bash CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver npm install appium-chromedriver @@ -77,7 +71,7 @@ the server returns a proper list of stored drivers in response to requests havin Since version 5.6 the second environment variable has been added: `CHROMELABS_URL`. By default, it points to https://googlechromelabs.github.io, and is expected to contain the actual prefix of [Chrome for Testing availability](https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints) -JSON API. This API allows retrieval of chromedrivers whose versions are greater than 114. +JSON API. This API allows retrieval of chromedrivers whose major versions are greater than `114`. Similarly to the above it could be also defined in the .npmrc file: diff --git a/install-npm.js b/install-npm.js deleted file mode 100755 index 2d35c39..0000000 --- a/install-npm.js +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env node - -/** - * This is the `postinstall` script which: - * 1. Builds the project if it isn't yet built (only happens in a dev environment), and - * 2. Downloads Chromedriver (which can be disabled); - * - * Because `prepare` is run _after_ `postinstall`, we cannot just use `prepare` to build the project - * because this script depends on the project being built! - */ - -const B = require('bluebird'); -const util = require('util'); - -// this is here because we're using async/await, and this must be set _before_ we use async/await, -// given that bluebird is used elsewhere via `doInstall()`. -B.config({ - cancellation: true, -}); - -const fs = require('fs/promises'); -const path = require('path'); -const _ = require('lodash'); -const {exec} = require('teen_process'); -const {logger} = require('@appium/support'); - -const log = logger.getLogger('CDInstaller'); -const BUILD_PATH = path.join(__dirname, 'build', 'lib', 'install.js'); - -async function main() { - // always build if not yet built. - // this should only happen in a working copy / dev environment. - try { - await fs.stat(BUILD_PATH); - } catch { - log.info( - `The Chromedriver install script cannot be found at '${BUILD_PATH}'. ` + - `Building appium-chromedriver package` - ); - const isWindows = process.platform === 'win32'; - const npmCommand = `npm${isWindows ? '.cmd' : ''}`; - try { - await exec(npmCommand, ['run', 'build'], { - logger: log, - cwd: __dirname, - shell: isWindows, - }); - } catch (e) { - throw new Error(`appium-chromedriver package cannot be built: ${util.inspect(e)}`); - } - } - - // check if we should skip install - if ( - !_.isEmpty(process.env.APPIUM_SKIP_CHROMEDRIVER_INSTALL) || - !_.isEmpty(process.env.npm_config_chromedriver_skip_install) - ) { - log.warn( - `'APPIUM_SKIP_CHROMEDRIVER_INSTALL' environment variable is set; skipping Chromedriver installation.` - ); - log.warn(`Android web/hybrid testing will not be possible without Chromedriver.`); - return; - } - - try { - await require(BUILD_PATH).doInstall(); - } catch (err) { - log.error(`Error installing Chromedriver: ${err.message}`); - log.error(err.stack ? err.stack : err); - log.error( - `Downloading Chromedriver can be skipped by setting the` + - `'APPIUM_SKIP_CHROMEDRIVER_INSTALL' environment variable.` - ); - process.exit(1); - } -} - -if (require.main === module) { - main(); -} diff --git a/package.json b/package.json index 0fd9157..afaa368 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ }, "files": [ "config", - "install-npm.js", "lib", "build", "!build/test", @@ -62,7 +61,6 @@ "dev": "npm run build -- --watch", "lint": "eslint .", "lint:fix": "npm run lint -- --fix", - "postinstall": "node install-npm.js", "prepare": "npm run build", "format": "prettier -w ./lib", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", diff --git a/test/functional/chromedriver-e2e-specs.js b/test/functional/chromedriver-e2e-specs.js index c01e912..0d4d4f0 100644 --- a/test/functional/chromedriver-e2e-specs.js +++ b/test/functional/chromedriver-e2e-specs.js @@ -1,7 +1,7 @@ // transpile:mocha import {Chromedriver} from '../../lib/chromedriver'; -import {install} from '../../lib/install'; +import {install} from '../helpers/install'; import B from 'bluebird'; import {exec} from 'teen_process'; import _ from 'lodash'; diff --git a/test/functional/install-e2e-specs.js b/test/functional/install-e2e-specs.js deleted file mode 100644 index ab79445..0000000 --- a/test/functional/install-e2e-specs.js +++ /dev/null @@ -1,58 +0,0 @@ -import {fs} from '@appium/support'; -import {install} from '../../lib/install'; -import {CD_BASE_DIR, getChromedriverBinaryPath, getOsName} from '../../lib/utils'; -import {Chromedriver} from '../../lib/chromedriver'; - -let should; - -async function assertNoPreviousDirs() { - let err; - try { - await fs.stat(CD_BASE_DIR); - } catch (e) { - err = e; - } - should.exist(err); - err.code.should.eql('ENOENT'); -} - -describe('install scripts', function () { - this.timeout(2000000); - let chai; - - before(async function () { - chai = await import('chai'); - const chaiAsPromised = await import('chai-as-promised'); - - should = chai.should(); - chai.use(chaiAsPromised.default); - }); - - beforeEach(async function () { - await fs.rimraf(CD_BASE_DIR); - }); - - it('should install for this platform', async function () { - await assertNoPreviousDirs(); - await install(); - let cdPath = await getChromedriverBinaryPath(); - let cdStat = await fs.stat(cdPath); - cdStat.size.should.be.above(500000); - cdPath.should.contain(getOsName()); - let cd = new Chromedriver(); - await cd.initChromedriverPath(); - cd.chromedriver.should.equal(cdPath); - }); - it('should throw an error in chromedriver if nothing is installed', async function () { - await assertNoPreviousDirs(); - let cd = new Chromedriver(); - let err; - try { - await cd.initChromedriverPath(); - } catch (e) { - err = e; - } - should.exist(err); - err.message.should.contain('path'); - }); -}); diff --git a/lib/install.js b/test/helpers/install.js similarity index 84% rename from lib/install.js rename to test/helpers/install.js index 851a05a..cf9fb3c 100644 --- a/lib/install.js +++ b/test/helpers/install.js @@ -1,11 +1,11 @@ import _ from 'lodash'; import { fs, mkdirp } from '@appium/support'; -import ChromedriverStorageClient from './storage-client/storage-client'; -import {parseLatestKnownGoodVersionsJson} from './storage-client/chromelabs'; +import ChromedriverStorageClient from '../../lib/storage-client/storage-client'; +import {parseLatestKnownGoodVersionsJson} from '../../lib/storage-client/chromelabs'; import { CD_VER, retrieveData, getOsInfo, getChromedriverDir, -} from './utils'; -import { USER_AGENT, STORAGE_REQ_TIMEOUT_MS, CHROMELABS_URL } from './constants'; +} from '../../lib/utils'; +import { USER_AGENT, STORAGE_REQ_TIMEOUT_MS, CHROMELABS_URL } from '../../lib/constants'; const LATEST_VERSION = 'LATEST'; @@ -49,7 +49,7 @@ async function prepareChromedriverDir (platformName) { return chromedriverDir; } -async function install () { +export async function install () { const osInfo = await getOsInfo(); const client = new ChromedriverStorageClient({ chromedriverDir: await prepareChromedriverDir(osInfo.name), @@ -59,9 +59,3 @@ async function install () { versions: [await formatCdVersion(CD_VER)], }); } - -async function doInstall () { - await install(); -} - -export { install, doInstall };