Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
182 changes: 127 additions & 55 deletions lib/binaries/chrome_xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,78 +63,150 @@ export class ChromeXml extends XmlConfigSource {
*/
private getLatestChromeDriverVersion(): Promise<BinaryUrl> {
return this.getVersionList().then(list => {
let chromedriverVersion: string = null;
let latest = '';
let latestVersion = '';
for (let item of list) {
// Get a semantic version
const version = item.split('/')[0];
if (semver.valid(version) == null) {
const iterVersion = getValidSemver(version);

if (!semver.valid(iterVersion)) {
throw new Error('invalid Chromedriver version');
}
// First time: use the version found.
if (chromedriverVersion == null) {
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (
let chromedriverVersion: string = null;
// To support 4-number versions (e.g. 76.0.3809.68)
let chromedriverPatchVersion: string = null;
let latest = '';
let latestVersion = '';
for (let item of list) {
// Get a semantic version
const version = item.split('/')[0];
const isLong = version.split('.').length === 4;

if (semver.valid(version) == null) {
let iterVersion;
let iterPatchVersion;
if (!isLong) {
iterVersion = getValidSemver(version);
} else {
// At first check first 3 numbers of version (for e.g. 76.0.3809.68)
iterVersion = getValidSemver(version.split('.').slice(0, 3).join('.'));
iterPatchVersion = getValidSemver(version.split('.').slice(1, 4).join('.'));
}

if (!semver.valid(iterVersion)) {
throw new Error('invalid Chromedriver version');
}
// First time: use the version found.
if (chromedriverVersion == null) {
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (
iterVersion.startsWith(this.maxVersion) &&
semver.gt(iterVersion, chromedriverVersion)) {
// After the first time, make sure the semantic version is greater.
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} 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') {
if (item.includes(this.getOsTypeName() + '64')) {
latest = item;
// After the first time, make sure the semantic version is greater.
chromedriverVersion = iterVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (iterVersion === chromedriverVersion) {
if (isLong && iterPatchVersion != chromedriverPatchVersion)
// Now check last 3 numbers of version to include patch (for e.g. 76.0.3809.68)
{
if (chromedriverPatchVersion == null) {
chromedriverPatchVersion = iterPatchVersion;
latest = item;
latestVersion = item.split('/')[0];
} else if (semver.gt(iterPatchVersion, chromedriverPatchVersion)) {
// After the first time, make sure the semantic version is greater.
chromedriverPatchVersion = iterPatchVersion;
latest = item;
latestVersion = item.split('/')[0];
}
} else {
// If the semantic version is the same, check os arch.
// For 64-bit systems, prefer the 64-bit version.
if (this.osarch === 'x64') {
if (item.includes(this.getOsTypeName() + '64')) {
latest = item;
}
}
}
}
}
}
return {url: Config.cdnUrls().chrome + latest, version: latestVersion};
}
return {url: Config.cdnUrls().chrome + latest, version: latestVersion};
});
);
}

/**
* Gets a specific item from the XML.
*/
private getSpecificChromeDriverVersion(inputVersion: string): Promise<BinaryUrl> {
return this.getVersionList().then(list => {
const specificVersion = getValidSemver(inputVersion);
if (specificVersion === '') {
throw new Error(`version ${inputVersion} ChromeDriver does not exist`)
}

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

if (semver.valid(lookUpVersion)) {
// Check to see if the specified version matches.
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 == '') {
if (this.osarch === 'x64' ||

if (!isLong) {
const specificVersion = getValidSemver(inputVersion);
if (specificVersion === '') {
throw new Error(`version ${inputVersion} ChromeDriver does not exist`)
}
for (let item of list) {
// Get a semantic version.
let version = item.split('/')[0];
if (semver.valid(version) == null) {
const lookUpVersion = getValidSemver(version);

if (semver.valid(lookUpVersion)) {
// Check to see if the specified version matches.
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 == '') {
if (this.osarch === 'x64' ||
(this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) {
itemFound = item;
}
itemFound = item;
}

}
// If the semantic version is the same, check os arch.
// For 64-bit systems, prefer the 64-bit version.
else if (this.osarch === 'x64') {
if (item.includes(this.getOsTypeName() + '64')) {
itemFound = item;
}
}
}
// If the semantic version is the same, check os arch.
// For 64-bit systems, prefer the 64-bit version.
else if (this.osarch === 'x64') {
if (item.includes(this.getOsTypeName() + '64')) {
itemFound = item;
}
}
}
} else {
// Splitting to two semver objects because of clunky chromedriver versioning
// Supports e.g. 76.0.3809.68 while not ignoring the last patch number
const inputVersionPart1 = inputVersion.split('.').slice(0, 3).join('.');
const inputVersionPart2 = inputVersion.split('.').slice(1, 4).join('.');

const specificVersion1 = getValidSemver(inputVersionPart1);
const specificVersion2 = getValidSemver(inputVersionPart2);
if (specificVersion1 === '' || specificVersion2 === '') {
throw new Error(`version ${inputVersion} ChromeDriver does not exist`);
}

for (let item of list) {
// Get a semantic version.
let version = item.split('/')[0];
if (semver.valid(version) == null) {
const versionPt1 = version.split('.').slice(0, 3).join('.');
const versionPt2 = version.split('.').slice(1, 4).join('.');
const lookUpVersion1 = getValidSemver(versionPt1);
const lookUpVersion2 = getValidSemver(versionPt2);
if (semver.valid(lookUpVersion1) && semver.valid(lookUpVersion2)) {
// Check to see if the specified version matches.
if (lookUpVersion1 === specificVersion1 && lookUpVersion2 === specificVersion2) {
// 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 == '') {
if (this.osarch === 'x64' ||
(this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) {
itemFound = item;
}
} else if (this.osarch === 'x64') {
if (item.includes(this.getOsTypeName() + '64')) {
itemFound = item;
}
}
}
}
Expand Down Expand Up @@ -176,7 +248,7 @@ export function getValidSemver(version: string): string {
}
// This supports downloading 74.0.3729.6
try {
const newRegex = /(\d+.\d+.\d+).\d+/g;
const newRegex = /(\d+.\d+.\d+)/g;
const exec = newRegex.exec(version);
if (exec) {
lookUpVersion = exec[1];
Expand Down
22 changes: 22 additions & 0 deletions spec/binaries/chrome_xml_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,26 @@ describe('chrome xml reader', () => {
done();
});
});

it('should get 76.0.3809.68 version', (done) => {
let chromeXml = new ChromeXml();
chromeXml.out_dir = out_dir;
chromeXml.ostype = 'Windows_NT';
chromeXml.osarch = 'x64';
chromeXml.getUrl('76.0.3809.68').then((binaryUrl) => {
expect(binaryUrl.url).toContain('76.0.3809.68/chromedriver_win32.zip');
done();
});
});

it('should get 76.0.3809.12 version', (done) => {
let chromeXml = new ChromeXml();
chromeXml.out_dir = out_dir;
chromeXml.ostype = 'Windows_NT';
chromeXml.osarch = 'x64';
chromeXml.getUrl('76.0.3809.12').then((binaryUrl) => {
expect(binaryUrl.url).toContain('76.0.3809.12/chromedriver_win32.zip');
done();
});
});
});