Skip to content

Commit 0a6ce24

Browse files
authored
fix(chromedriver): version fixes for update, status, and start (#380)
- Set the max versioning set in config.json. This will need to be updated on every release of chromedriver. This will "fix" chrome and chromedriver mismatches until Chrome 75 comes out. When it does there will have to be an update for this again. Possible future work would allow a user to set this via flag. Example --maxVersions.chrome "74." - Create a generic way to get a valid version for Chromedriver. If presented with 2.x, change this to 2.x.0. If presented with a 74.x.x.x, chop off the last set of numbers and change this to 74.x.x - Fixes the status command during a semver check. - Fixes the update and start command when starting a specific version of chromedriver
1 parent 1d3a3bc commit 0a6ce24

File tree

4 files changed

+60
-34
lines changed

4 files changed

+60
-34
lines changed

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"webdriverVersions": {
33
"selenium": "2.53.1",
44
"chromedriver": "2.27",
5+
"maxChromedriver": "74",
56
"geckodriver": "v0.13.0",
67
"iedriver": "2.53.1",
78
"androidsdk": "24.4.1",

lib/binaries/chrome_xml.ts

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {BinaryUrl} from './binary';
66
import {XmlConfigSource} from './config_source';
77

88
export class ChromeXml extends XmlConfigSource {
9+
maxVersion = Config.binaryVersions().maxChrome;
10+
911
constructor() {
1012
super('chrome', Config.cdnUrls()['chrome']);
1113
}
@@ -66,44 +68,26 @@ export class ChromeXml extends XmlConfigSource {
6668
let latestVersion = '';
6769
for (let item of list) {
6870
// Get a semantic version
69-
let version = item.split('/')[0];
71+
const version = item.split('/')[0];
7072
if (semver.valid(version) == null) {
71-
// This supports downloading 74.0.3729.6
72-
try {
73-
const newRegex = /(\d+.\d+.\d+).\d+/g;
74-
const exec = newRegex.exec(version);
75-
if (exec) {
76-
version = exec[1];
77-
}
78-
} catch (_) {
79-
// no-op: if this does not work, use the other regex pattern.
80-
}
73+
const iterVersion = getValidSemver(version);
8174

82-
// This supports downloading 2.46
83-
try {
84-
const oldRegex = /(\d+.\d+)/g;
85-
const exec = oldRegex.exec(version);
86-
if (exec) {
87-
version = exec[1] + '.0';
88-
}
89-
} catch (_) {
90-
// no-op: is this is not valid, do not throw here.
91-
}
92-
93-
if (!semver.valid(version)) {
75+
if (!semver.valid(iterVersion)) {
9476
throw new Error('invalid Chromedriver version');
9577
}
9678
// First time: use the version found.
9779
if (chromedriverVersion == null) {
98-
chromedriverVersion = version;
80+
chromedriverVersion = iterVersion;
9981
latest = item;
10082
latestVersion = item.split('/')[0];
101-
} else if (semver.gt(version, chromedriverVersion)) {
83+
} else if (
84+
iterVersion.startsWith(this.maxVersion) &&
85+
semver.gt(iterVersion, chromedriverVersion)) {
10286
// After the first time, make sure the semantic version is greater.
103-
chromedriverVersion = version;
87+
chromedriverVersion = iterVersion;
10488
latest = item;
10589
latestVersion = item.split('/')[0];
106-
} else if (version === chromedriverVersion) {
90+
} else if (iterVersion === chromedriverVersion) {
10791
// If the semantic version is the same, check os arch.
10892
// For 64-bit systems, prefer the 64-bit version.
10993
if (this.osarch === 'x64') {
@@ -123,17 +107,18 @@ export class ChromeXml extends XmlConfigSource {
123107
*/
124108
private getSpecificChromeDriverVersion(inputVersion: string): Promise<BinaryUrl> {
125109
return this.getVersionList().then(list => {
126-
let itemFound = '';
127-
let specificVersion = semver.valid(inputVersion) ? inputVersion : inputVersion + '.0';
110+
const specificVersion = getValidSemver(inputVersion);
128111

112+
let itemFound = '';
129113
for (let item of list) {
130114
// Get a semantic version.
131115
let version = item.split('/')[0];
132116
if (semver.valid(version) == null) {
133-
version += '.0';
134-
if (semver.valid(version)) {
117+
const lookUpVersion = getValidSemver(version);
118+
119+
if (semver.valid(lookUpVersion)) {
135120
// Check to see if the specified version matches.
136-
if (version === specificVersion) {
121+
if (lookUpVersion === specificVersion) {
137122
// When item found is null, check the os arch
138123
// 64-bit version works OR not 64-bit version and the path does not have '64'
139124
if (itemFound == '') {
@@ -162,3 +147,40 @@ export class ChromeXml extends XmlConfigSource {
162147
});
163148
}
164149
}
150+
151+
/**
152+
* Chromedriver is the only binary that does not conform to semantic versioning
153+
* and either has too little number of digits or too many. To get this to be in
154+
* semver, we will either add a '.0' at the end or chop off the last set of
155+
* digits. This is so we can compare to find the latest and greatest.
156+
*
157+
* Example:
158+
* 2.46 -> 2.46.0
159+
* 75.0.3770.8 -> 75.0.3770
160+
*
161+
* @param version
162+
*/
163+
export function getValidSemver(version: string): string {
164+
let lookUpVersion = '';
165+
// This supports downloading 2.46
166+
try {
167+
const oldRegex = /(\d+.\d+)/g;
168+
const exec = oldRegex.exec(version);
169+
if (exec) {
170+
lookUpVersion = exec[1] + '.0';
171+
}
172+
} catch (_) {
173+
// no-op: is this is not valid, do not throw here.
174+
}
175+
// This supports downloading 74.0.3729.6
176+
try {
177+
const newRegex = /(\d+.\d+.\d+).\d+/g;
178+
const exec = newRegex.exec(version);
179+
if (exec) {
180+
lookUpVersion = exec[1];
181+
}
182+
} catch (_) {
183+
// no-op: if this does not work, use the other regex pattern.
184+
}
185+
return lookUpVersion;
186+
}

lib/cmds/status.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from 'path';
44
import * as semver from 'semver';
55

66
import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, Standalone} from '../binaries';
7+
import {getValidSemver} from '../binaries/chrome_xml';
78
import {Logger, Options, Program} from '../cli';
89
import {Config} from '../config';
910
import {FileManager} from '../files';
@@ -88,8 +89,8 @@ function status(options: Options) {
8889
// - last: the last binary downloaded by webdriver-manager per the update-config.json
8990
downloaded.versions = downloaded.versions.sort((a: string, b: string): number => {
9091
if (!semver.valid(a)) {
91-
a += '.0';
92-
b += '.0';
92+
a = getValidSemver(a);
93+
b = getValidSemver(b);
9394
}
9495
if (semver.gt(a, b)) {
9596
return 1;

lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ConfigFile {
1515
ie?: string;
1616
android?: string;
1717
appium?: string;
18+
maxChrome?: string;
1819
}
1920

2021
/**
@@ -94,6 +95,7 @@ export class Config {
9495
configVersions.ie = configFile.webdriverVersions.iedriver;
9596
configVersions.android = configFile.webdriverVersions.androidsdk;
9697
configVersions.appium = configFile.webdriverVersions.appium;
98+
configVersions.maxChrome = configFile.webdriverVersions.maxChromedriver;
9799
return configVersions;
98100
}
99101

0 commit comments

Comments
 (0)