diff --git a/lib/binaries/chrome_xml.ts b/lib/binaries/chrome_xml.ts index 3ab6fca8..3c8ee91e 100644 --- a/lib/binaries/chrome_xml.ts +++ b/lib/binaries/chrome_xml.ts @@ -74,34 +74,77 @@ export class ChromeXml extends XmlConfigSource { */ private getSpecificChromeDriverVersion(inputVersion: string): Promise { 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' || - (this.osarch !== 'x64' && !item.includes(this.getOsTypeName() + '64'))) { - itemFound = item; - } + 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; + } + + } + // 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; + } } } } @@ -143,7 +186,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]; diff --git a/spec/binaries/chrome_xml_spec.ts b/spec/binaries/chrome_xml_spec.ts index 5a8ab8a7..7620de8c 100644 --- a/spec/binaries/chrome_xml_spec.ts +++ b/spec/binaries/chrome_xml_spec.ts @@ -65,4 +65,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(); + }); + }); });