forked from shaka-project/webdriver-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·87 lines (78 loc) · 2.5 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
/*! @license
* WebDriver Installer
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
const {ChromeWebDriverInstaller} = require('./chrome.js');
const {ChromeAndroidWebDriverInstaller} = require('./chrome-android.js');
const {FirefoxWebDriverInstaller} = require('./firefox.js');
const {EdgeWebDriverInstaller} = require('./edge.js');
const INSTALLER_CLASSES = [
ChromeWebDriverInstaller,
ChromeAndroidWebDriverInstaller,
FirefoxWebDriverInstaller,
EdgeWebDriverInstaller,
];
/**
* Install drivers to match all detected browsers.
*
* @param {string=} outputDirectory Defaults to ./
* @param {boolean=} logging
* @return {!Promise}
*/
async function main(outputDirectory='.', logging=true) {
if (logging) {
console.log(`Installing binaries to ${outputDirectory}`);
}
for (const InstallerClass of INSTALLER_CLASSES) {
const installer = new InstallerClass();
const browserName = installer.getBrowserName();
const driverName = installer.getDriverName();
const browserVersion = await installer.getInstalledBrowserVersion();
if (browserVersion == null) {
if (logging) {
console.log(`${browserName} not found.`);
}
} else {
const installedDriverVersion =
await installer.getInstalledDriverVersion(outputDirectory);
const bestDriverVersion =
await installer.getBestDriverVersion(browserVersion);
if (installedDriverVersion == bestDriverVersion) {
if (logging) {
console.log(
`Version ${installedDriverVersion} of ${driverName} already` +
` installed for ${browserName} version ${browserVersion}`);
}
} else {
await installer.install(bestDriverVersion, outputDirectory);
if (logging) {
console.log(
`Installed version ${bestDriverVersion} of ${driverName}` +
` for ${browserName} version ${browserVersion}`);
}
}
}
}
}
if (require.main == module) {
// Skip argv[0], which is node, and argv[1], which is this script name.
const args = process.argv.slice(2);
const HELP_ARGS = ['--help', '-h', '-?'];
if (args.length > 1 || HELP_ARGS.includes(args[0])) {
process.stderr.write(`Usage: ${process.argv[1]} [OUTPUT_DIR]\n`);
process.exit(1);
}
(async () => {
try {
await main(args[0]);
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
})();
} else {
module.exports = {installWebDrivers: main};
}