Skip to content

Commit 375f6ff

Browse files
authored
Add support for downloading chromedriver v91. (#13)
1 parent 6aad9a7 commit 375f6ff

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

src/commands/android/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const AVAILABLE_OPTIONS: AvailableOptions = {
2929

3030
export const NIGHTWATCH_AVD = 'nightwatch-android-11';
3131
export const DEFAULT_FIREFOX_VERSION = '105.1.0';
32-
export const DEFAULT_CHROME_VERSION = '83.0.4103.106';
32+
export const DEFAULT_CHROME_VERSIONS = ['83', '91'];
3333

3434
export const ABI = (() => {
3535
const arch = process.arch;

src/commands/android/downloads.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
"windows": "https://dl.google.com/android/repository/commandlinetools-win-8512546_latest.zip"
66
},
77
"chromedriver": {
8-
"mac": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_mac64.zip",
9-
"linux": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip",
10-
"windows": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_win32.zip"
8+
"83": {
9+
"mac": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_mac64.zip",
10+
"linux": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip",
11+
"windows": "https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_win32.zip"
12+
},
13+
"91": {
14+
"mac": "https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_mac64.zip",
15+
"linux": "https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_linux64.zip",
16+
"windows": "https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_win32.zip"
17+
}
1118
}
1219
}

src/commands/android/index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import os from 'os';
66
import path from 'path';
77
import untildify from 'untildify';
88
import {prompt} from 'inquirer';
9+
import boxen from 'boxen';
910

1011
import Logger from '../../logger';
1112
import {getPlatformName, symbols} from '../../utils';
1213
import {getAlreadyRunningAvd, killEmulatorWithoutWait, launchAVD} from './adb';
1314
import {
14-
ABI, AVAILABLE_OPTIONS, BINARY_TO_PACKAGE_NAME, DEFAULT_CHROME_VERSION,
15+
ABI, AVAILABLE_OPTIONS, BINARY_TO_PACKAGE_NAME, DEFAULT_CHROME_VERSIONS,
1516
DEFAULT_FIREFOX_VERSION, NIGHTWATCH_AVD, SETUP_CONFIG_QUES
1617
} from './constants';
1718
import {AndroidSetupResult, Options, OtherInfo, Platform, SdkBinary, SetupConfigs} from './interfaces';
@@ -736,7 +737,7 @@ export class AndroidSetup {
736737
const verifyChrome = browsers.includes('chrome');
737738

738739
let firefoxLatestVersion = '';
739-
let installedChromeVersion = DEFAULT_CHROME_VERSION;
740+
let installedChromeVersion = '';
740741

741742
let installFirefox = false;
742743
let downloadChromedriver = false;
@@ -921,11 +922,13 @@ export class AndroidSetup {
921922
}
922923

923924
if (downloadChromedriver) {
924-
if (installedChromeVersion === DEFAULT_CHROME_VERSION) {
925+
const chromeMajorVersion = installedChromeVersion.split('.')[0];
926+
if (DEFAULT_CHROME_VERSIONS.includes(chromeMajorVersion)) {
925927
Logger.log('Downloading chromedriver to work with the factory version of Chrome browser...');
926928

929+
const chromedriverDownloadLink = (DOWNLOADS.chromedriver as any)[chromeMajorVersion][this.platform];
927930
const result = await downloadWithProgressBar(
928-
DOWNLOADS.chromedriver[this.platform],
931+
chromedriverDownloadLink,
929932
chromedriverDownloadDir,
930933
true
931934
);
@@ -935,7 +938,7 @@ export class AndroidSetup {
935938
status.setupChrome = true;
936939
} else {
937940
Logger.log(`\n${colors.red('Failed!')} You can download the chromedriver yourself from the below link:`);
938-
Logger.log(colors.cyan(` ${DOWNLOADS.chromedriver[this.platform]}`));
941+
Logger.log(colors.cyan(` ${chromedriverDownloadLink}`));
939942
Logger.log(
940943
' (Extract and copy the chromedriver binary and paste it in your Nightwatch project inside \'chromedriver-mobile\' folder.)',
941944
'\n'
@@ -945,16 +948,17 @@ export class AndroidSetup {
945948
if (status.setupChrome) {
946949
Logger.log('You can run your tests now on your Android Emulator\'s Chrome browser.\n');
947950
}
951+
} else if (installedChromeVersion === '') {
952+
Logger.log(colors.red(symbols().fail), 'chromedriver could not be downloaded (installed browser version unknown).\n');
948953
} else {
949-
Logger.log(colors.cyan('[CHROMEDRIVER]'));
950-
Logger.log('Installed Chrome browser version is different from factory version.\n');
951-
Logger.log('You can download the chromedriver for current version from the below link:');
952-
Logger.log(colors.cyan(' https://chromedriver.storage.googleapis.com/index.html'));
953-
Logger.log(
954-
' (Extract and copy the chromedriver binary and paste it in your Nightwatch project inside \'chromedriver-mobile\' folder.)',
955-
'\n'
956-
);
957-
status.setupChrome = true; // because we have done what we could do, i.e., setup from our side is complete.
954+
Logger.log(boxen(
955+
colors.cyan('[CHROMEDRIVER]\n\n') +
956+
colors.red('Could not download chromedriver (installed Chrome version is different from the factory versions).\n\n') +
957+
'You can download chromedriver for the installed Chrome version from the below link:\n' +
958+
colors.cyan(' https://chromedriver.storage.googleapis.com/index.html\n\n') +
959+
'After downloading, extract the zip file, copy the extracted chromedriver binary, and put in inside \'chromedriver-mobile\' folder in your Nightwatch project.',
960+
{padding: 1}
961+
), '\n');
958962
}
959963
}
960964
}
@@ -995,7 +999,7 @@ export class AndroidSetup {
995999
}
9961000
} else {
9971001
Logger.log(`${colors.red('Error:')} Some requirements failed to set up.`);
998-
Logger.log('Please try running the failed commands by yourself and then re-run this tool.\n');
1002+
Logger.log('Please look for the errors above and try running any failed commands by yourself and then re-run this tool.\n');
9991003

10001004
Logger.log('If it still fails, please raise an issue with us at:');
10011005
Logger.log(colors.cyan(' https://github.com/nightwatchjs/mobile-helper-tool/issues'), '\n');

src/commands/android/utils/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import path from 'path';
88
import which from 'which';
99

1010
import {symbols} from '../../../utils';
11-
import {ABI, AVAILABLE_OPTIONS, DEFAULT_CHROME_VERSION, DEFAULT_FIREFOX_VERSION, SDK_BINARY_LOCATIONS} from '../constants';
11+
import {ABI, AVAILABLE_OPTIONS, DEFAULT_CHROME_VERSIONS, DEFAULT_FIREFOX_VERSION, SDK_BINARY_LOCATIONS} from '../constants';
1212
import {Platform, SdkBinary} from '../interfaces';
1313

1414
export const getAllAvailableOptions = () => {
@@ -126,7 +126,7 @@ export const getLatestVersion = async (browser: 'firefox' | 'chrome'): Promise<s
126126
return DEFAULT_FIREFOX_VERSION;
127127
}
128128
} else {
129-
return DEFAULT_CHROME_VERSION;
129+
return DEFAULT_CHROME_VERSIONS[1];
130130
}
131131
};
132132

tests/unit_tests/commands/android/testUtilsGetLatestVersion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ describe('test getAllAvailableOptions', function() {
4646
const {getLatestVersion} = require('../../../../src/commands/android/utils/common');
4747
const version = await getLatestVersion('chrome');
4848

49-
assert.strictEqual(version, '83.0.4103.106');
49+
assert.strictEqual(version, '91');
5050
});
5151
});

0 commit comments

Comments
 (0)