Skip to content

fix(chromedriver): version fixes for update, status, and start #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"webdriverVersions": {
"selenium": "2.53.1",
"chromedriver": "2.27",
"maxChromedriver": "74",
"geckodriver": "v0.13.0",
"iedriver": "2.53.1",
"androidsdk": "24.4.1",
Expand Down
86 changes: 54 additions & 32 deletions lib/binaries/chrome_xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {BinaryUrl} from './binary';
import {XmlConfigSource} from './config_source';

export class ChromeXml extends XmlConfigSource {
maxVersion = Config.binaryVersions().maxChrome;

constructor() {
super('chrome', Config.cdnUrls()['chrome']);
}
Expand Down Expand Up @@ -66,44 +68,26 @@ export class ChromeXml extends XmlConfigSource {
let latestVersion = '';
for (let item of list) {
// Get a semantic version
let version = item.split('/')[0];
const version = item.split('/')[0];
if (semver.valid(version) == null) {
// This supports downloading 74.0.3729.6
try {
const newRegex = /(\d+.\d+.\d+).\d+/g;
const exec = newRegex.exec(version);
if (exec) {
version = exec[1];
}
} catch (_) {
// no-op: if this does not work, use the other regex pattern.
}
const iterVersion = getValidSemver(version);

// This supports downloading 2.46
try {
const oldRegex = /(\d+.\d+)/g;
const exec = oldRegex.exec(version);
if (exec) {
version = exec[1] + '.0';
}
} catch (_) {
// no-op: is this is not valid, do not throw here.
}

if (!semver.valid(version)) {
if (!semver.valid(iterVersion)) {
throw new Error('invalid Chromedriver version');
}
// First time: use the version found.
if (chromedriverVersion == null) {
chromedriverVersion = version;
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (semver.gt(version, chromedriverVersion)) {
} else if (
iterVersion.startsWith(this.maxVersion) &&
semver.gt(iterVersion, chromedriverVersion)) {
// After the first time, make sure the semantic version is greater.
chromedriverVersion = version;
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (version === chromedriverVersion) {
} else if (iterVersion === chromedriverVersion) {
// If the semantic version is the same, check os arch.
// For 64-bit systems, prefer the 64-bit version.
if (this.osarch === 'x64') {
Expand All @@ -123,17 +107,18 @@ export class ChromeXml extends XmlConfigSource {
*/
private getSpecificChromeDriverVersion(inputVersion: string): Promise<BinaryUrl> {
return this.getVersionList().then(list => {
let itemFound = '';
let specificVersion = semver.valid(inputVersion) ? inputVersion : inputVersion + '.0';
const specificVersion = getValidSemver(inputVersion);

let itemFound = '';
for (let item of list) {
// Get a semantic version.
let version = item.split('/')[0];
if (semver.valid(version) == null) {
version += '.0';
if (semver.valid(version)) {
const lookUpVersion = getValidSemver(version);

if (semver.valid(lookUpVersion)) {
// Check to see if the specified version matches.
if (version === specificVersion) {
if (lookUpVersion === specificVersion) {
// When item found is null, check the os arch
// 64-bit version works OR not 64-bit version and the path does not have '64'
if (itemFound == '') {
Expand Down Expand Up @@ -162,3 +147,40 @@ export class ChromeXml extends XmlConfigSource {
});
}
}

/**
* Chromedriver is the only binary that does not conform to semantic versioning
* and either has too little number of digits or too many. To get this to be in
* semver, we will either add a '.0' at the end or chop off the last set of
* digits. This is so we can compare to find the latest and greatest.
*
* Example:
* 2.46 -> 2.46.0
* 75.0.3770.8 -> 75.0.3770
*
* @param version
*/
export function getValidSemver(version: string): string {
let lookUpVersion = '';
// This supports downloading 2.46
try {
const oldRegex = /(\d+.\d+)/g;
const exec = oldRegex.exec(version);
if (exec) {
lookUpVersion = exec[1] + '.0';
}
} catch (_) {
// no-op: is this is not valid, do not throw here.
}
// This supports downloading 74.0.3729.6
try {
const newRegex = /(\d+.\d+.\d+).\d+/g;
const exec = newRegex.exec(version);
if (exec) {
lookUpVersion = exec[1];
}
} catch (_) {
// no-op: if this does not work, use the other regex pattern.
}
return lookUpVersion;
}
5 changes: 3 additions & 2 deletions lib/cmds/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import * as semver from 'semver';

import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, Standalone} from '../binaries';
import {getValidSemver} from '../binaries/chrome_xml';
import {Logger, Options, Program} from '../cli';
import {Config} from '../config';
import {FileManager} from '../files';
Expand Down Expand Up @@ -88,8 +89,8 @@ function status(options: Options) {
// - last: the last binary downloaded by webdriver-manager per the update-config.json
downloaded.versions = downloaded.versions.sort((a: string, b: string): number => {
if (!semver.valid(a)) {
a += '.0';
b += '.0';
a = getValidSemver(a);
b = getValidSemver(b);
}
if (semver.gt(a, b)) {
return 1;
Expand Down
2 changes: 2 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ConfigFile {
ie?: string;
android?: string;
appium?: string;
maxChrome?: string;
}

/**
Expand Down Expand Up @@ -94,6 +95,7 @@ export class Config {
configVersions.ie = configFile.webdriverVersions.iedriver;
configVersions.android = configFile.webdriverVersions.androidsdk;
configVersions.appium = configFile.webdriverVersions.appium;
configVersions.maxChrome = configFile.webdriverVersions.maxChromedriver;
return configVersions;
}

Expand Down