forked from okta/samples-nodejs-express-4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-se-drivers.js
More file actions
42 lines (35 loc) · 1.5 KB
/
update-se-drivers.js
File metadata and controls
42 lines (35 loc) · 1.5 KB
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
const axios = require('axios');
const { execSync, execFileSync } = require('child_process');
function getOS() {
let os = process.platform;
if (os === 'darwin') {
os = 'MacOS';
} else if (os === 'win32' || os === 'win64') {
os = 'Windows';
} else if (os === 'linux') {
os = 'Linux';
}
return os;
}
const os = getOS();
console.log(`Operating System - ${os}`);
let chromeVersion;
if (os === 'MacOS') {
const chromeVersionString = execSync('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version').toString();
// Get the major and minor version of the chrome version using regex (1 or more digits followed by a dot followed by 1 or more digits)
const matchIndex = 0;
chromeVersion = chromeVersionString.match(/(\d+(\.\d+)?)/)[matchIndex];
} else {
chromeVersion = execSync('google-chrome --product-version').toString();
}
const chromeMajorVersion = chromeVersion.split('.')[0];
console.log(`Chrome Major Version - ${chromeMajorVersion}`);
const chromeDriverUrl = `https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chromeMajorVersion}`;
axios.get(chromeDriverUrl).then((response) => {
const chromeDriverVersion = response.data;
console.log(`Chrome Driver Version - ${chromeDriverVersion}`);
execFileSync(`${__dirname}/../node_modules/protractor/bin/webdriver-manager`, ["update", "--versions.chrome", chromeDriverVersion, "--gecko", "false", "--versions.standalone", "latest"]);
console.log('Webdriver was updated');
}).catch((err) => {
console.log(err);
});