diff --git a/src/browser.ts b/src/browser.ts index 909024e1d..85e580d1e 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -3,11 +3,12 @@ import * as path from 'path'; import * as fs from 'fs-extra'; import { compareVersions } from 'compare-versions'; -import { WebDriver, Builder, until, initPageObjects, logging, By } from 'monaco-page-objects'; +import { WebDriver, Builder, until, initPageObjects, logging, By, Browser } from 'monaco-page-objects'; import { Options, ServiceBuilder } from 'selenium-webdriver/chrome'; import { getLocatorsPath } from 'vscode-extension-tester-locators'; import { CodeUtil, ReleaseQuality } from './util/codeUtil'; import { DEFAULT_STORAGE_FOLDER } from './extester'; +import { DriverUtil } from './util/driverUtil'; export class VSBrowser { static readonly baseVersion = '1.37.0'; @@ -85,10 +86,16 @@ export class VSBrowser { prefs.setLevel(logging.Type.DRIVER, this.logLevel); options.setLoggingPrefs(prefs); + const driverBinary = process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'; + let chromeDriverBinaryPath = path.join(this.storagePath, driverBinary); + if(this.codeVersion >= '1.86.0') { + chromeDriverBinaryPath = path.join(this.storagePath, `chromedriver-${DriverUtil.getChromeDriverPlatform()}`, driverBinary); + } + console.log('Launching browser...'); this._driver = await new Builder() - .setChromeService(new ServiceBuilder(path.join(this.storagePath, process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'))) - .forBrowser('chrome') + .setChromeService(new ServiceBuilder(chromeDriverBinaryPath)) + .forBrowser(Browser.CHROME) .setChromeOptions(options) .build(); VSBrowser._instance = this; diff --git a/src/extester.ts b/src/extester.ts index bbd56ab65..61b7129cb 100644 --- a/src/extester.ts +++ b/src/extester.ts @@ -128,7 +128,7 @@ export class ExTester { } else { console.log('Attempting Setup in offline mode'); const expectedChromeVersion = (await this.code.checkOfflineRequirements()).split('.')[0]; - const actualChromeVersion = (await this.chrome.checkDriverVersionOffline()).split('.')[0]; + const actualChromeVersion = (await this.chrome.checkDriverVersionOffline(vscodeParsedVersion)).split('.')[0]; if (expectedChromeVersion !== actualChromeVersion) { console.log('\x1b[33m%s\x1b[0m', `WARNING: Local copy of VS Code runs Chromium version ${expectedChromeVersion}, the installed ChromeDriver is version ${actualChromeVersion}.`) console.log(`Attempting with ChromeDriver ${actualChromeVersion} anyway. Tests may experience issues due to version mismatch.`); diff --git a/src/util/driverUtil.ts b/src/util/driverUtil.ts index d4b048b23..78863acb3 100644 --- a/src/util/driverUtil.ts +++ b/src/util/driverUtil.ts @@ -35,12 +35,12 @@ export class DriverUtil { * @param version version to download */ async downloadChromeDriver(version: string): Promise { - const majorVersion = version.split('.')[0]; - const file = path.join(this.downloadFolder, process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'); - if (fs.existsSync(file)) { + const url = this.getChromeDriverURL(version); + const driverBinary = this.getChromeDriverBinaryPath(version); + if (fs.existsSync(driverBinary)) { let localVersion = ''; try { - localVersion = await this.getLocalDriverVersion(); + localVersion = await this.getLocalDriverVersion(version); } catch (err) { // ignore and download } @@ -50,13 +50,7 @@ export class DriverUtil { } } fs.mkdirpSync(this.downloadFolder); - let driverPlatform = (process.platform === 'darwin') ? 'mac64' : process.platform === 'win32' ? 'win32' : 'linux64'; - let url = `https://chromedriver.storage.googleapis.com/${version}/chromedriver_${driverPlatform}.zip`; - if (+majorVersion > 114) { - // See formatting at https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json - driverPlatform = (process.platform === 'darwin') ? `mac-${process.arch}` : process.platform === 'win32' ? 'win32' : 'linux64'; - url = `https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${version}/${driverPlatform}/chromedriver-${driverPlatform}.zip` - } + const fileName = path.join(this.downloadFolder, path.basename(url)); console.log(`Downloading ChromeDriver ${version} from: ${url}`); await Download.getFile(url, fileName, true); @@ -64,15 +58,49 @@ export class DriverUtil { console.log(`Unpacking ChromeDriver ${version} into ${this.downloadFolder}`); await Unpack.unpack(fileName, this.downloadFolder); if (process.platform !== 'win32') { - fs.chmodSync(file, 0o755); + fs.chmodSync(driverBinary, 0o755); } console.log('Success!'); - return file; + return driverBinary; + } + + private getChromeDriverBinaryPath(version: string): string { + const majorVersion = version.split('.')[0]; + const binary = process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver'; + let driverBinaryPath = path.join(this.downloadFolder, binary); + if (+majorVersion > 114) { + driverBinaryPath = path.join(this.downloadFolder, `chromedriver-${DriverUtil.getChromeDriverPlatform()}`, binary); + } + return driverBinaryPath; + } + + static getChromeDriverPlatform(): string | undefined { + switch (process.platform) { + case 'darwin': + return `mac-${process.arch}`; + case 'win32': + return 'win32'; + case 'linux': + return 'linux64'; + default: + break; + } + return undefined; + } + + private getChromeDriverURL(version: string): string { + const majorVersion = version.split('.')[0]; + const driverPlatform = DriverUtil.getChromeDriverPlatform(); + let url = `https://chromedriver.storage.googleapis.com/${version}/chromedriver_${driverPlatform}.zip`; + if (+majorVersion > 114) { + url = `https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${version}/${driverPlatform}/chromedriver-${driverPlatform}.zip` + } + return url; } - async checkDriverVersionOffline(): Promise { + async checkDriverVersionOffline(version: string): Promise { try { - return await this.getLocalDriverVersion(); + return await this.getLocalDriverVersion(version); } catch (err) { console.log('ERROR: Cannot find a copy of ChromeDriver in local cache in offline mode, exiting.') throw err; @@ -82,8 +110,8 @@ export class DriverUtil { /** * Check local chrome driver version */ - private async getLocalDriverVersion(): Promise { - const command = `${path.join(this.downloadFolder, 'chromedriver')} -v`; + private async getLocalDriverVersion(version: string): Promise { + const command = `${this.getChromeDriverBinaryPath(version)} -v`; return new Promise((resolve, reject) => { child_process.exec(command, (err, stdout) => { if (err) return reject(err);