diff --git a/lib/cmds/initialize.ts b/lib/cmds/initialize.ts index 66006060..8851dd8d 100644 --- a/lib/cmds/initialize.ts +++ b/lib/cmds/initialize.ts @@ -245,8 +245,9 @@ export function android( 'android-sdk: Downloading more additional SDK updates ' + '(this may take a while)'); return downloadAndroidUpdates( - sdkPath, ['build-tools-24.0.0'].concat( - getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)), + sdkPath, + ['build-tools-24.0.0'].concat( + getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)), true, acceptLicenses, verbose); }) .then(() => { diff --git a/lib/cmds/opts.ts b/lib/cmds/opts.ts index ff9d9c5d..fde3795c 100644 --- a/lib/cmds/opts.ts +++ b/lib/cmds/opts.ts @@ -105,7 +105,8 @@ opts[STARTED_SIGNIFIER] = new Option( 'A string to be outputted once the selenium server is up and running. Useful if you are writing a script which uses webdriver-manager.', 'string'); opts[SIGNAL_VIA_IPC] = new Option( - SIGNAL_VIA_IPC, 'If you are using --' + STARTED_SIGNIFIER + + SIGNAL_VIA_IPC, + 'If you are using --' + STARTED_SIGNIFIER + ', this flag will emit the signal string using process.send(), rather than writing it to stdout', 'boolean', false); opts[DETACH] = new Option( diff --git a/lib/cmds/status.ts b/lib/cmds/status.ts index 385abc08..84072633 100644 --- a/lib/cmds/status.ts +++ b/lib/cmds/status.ts @@ -2,6 +2,7 @@ import * as fs from 'fs'; import * as minimist from 'minimist'; import * as path from 'path'; +import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, StandAlone} from '../binaries'; import {Logger, Options, Program} from '../cli'; import {Config} from '../config'; import {FileManager} from '../files'; @@ -49,19 +50,51 @@ function status(options: Options) { return; } + // Try to get the update-config.json. This will be used for showing the last binary downloaded. + let updateConfig: any = {}; + try { + updateConfig = + JSON.parse(fs.readFileSync(path.resolve(outputDir, 'update-config.json')).toString()) || {}; + } catch (err) { + updateConfig = {}; + } + let downloadedBinaries = FileManager.downloadedBinaries(outputDir); - // log which binaries have been downloaded + // Log which binaries have been downloaded. for (let bin in downloadedBinaries) { let downloaded = downloadedBinaries[bin]; let log = downloaded.name + ' '; log += downloaded.versions.length == 1 ? 'version available: ' : 'versions available: '; + + // Get the "last" downloaded binary from the updateConfig. + let last: string = null; + if (downloaded.binary instanceof Appium && updateConfig[Appium.id]) { + last = updateConfig[Appium.id]['last']; + } else if (downloaded.binary instanceof AndroidSDK && updateConfig[AndroidSDK.id]) { + last = updateConfig[AndroidSDK.id]['last']; + } else if (downloaded.binary instanceof ChromeDriver && updateConfig[ChromeDriver.id]) { + last = updateConfig[ChromeDriver.id]['last']; + } else if (downloaded.binary instanceof GeckoDriver && updateConfig[GeckoDriver.id]) { + last = updateConfig[GeckoDriver.id]['last']; + } else if (downloaded.binary instanceof IEDriver && updateConfig[IEDriver.id]) { + last = updateConfig[IEDriver.id]['last']; + } else if (downloaded.binary instanceof StandAlone && updateConfig[StandAlone.id]) { + last = updateConfig[StandAlone.id]['last']; + } + + // Log the versions: + // - default: the file associated with the config.json + // - last: the last binary downloaded by webdriver-manager per the update-config.json for (let ver in downloaded.versions) { let version = downloaded.versions[ver]; log += version; if (downloaded.binary.versionDefault() === version) { log += ' [default]'; } + if (last && last.indexOf(version) >= 0) { + log += ' [last]' + } if (+ver != downloaded.versions.length - 1) { log += ', '; } diff --git a/lib/cmds/update.ts b/lib/cmds/update.ts index 5babdf4a..c1eb31e4 100644 --- a/lib/cmds/update.ts +++ b/lib/cmds/update.ts @@ -167,6 +167,7 @@ function update(options: Options): Promise { let sdk_path = path.resolve(outputDir, binary.executableFilename(Config.osType())); let oldAVDList: string; + updateBrowserFile(binary, outputDir); promises.push(q.nfcall(fs.readFile, path.resolve(sdk_path, 'available_avds.json')) .then( (oldAVDs: string) => { @@ -190,6 +191,7 @@ function update(options: Options): Promise { checkIOS(logger); } if (android || ios) { + updateBrowserFile(binaries[Appium.id], outputDir); installAppium(binaries[Appium.id], outputDir); } diff --git a/spec/cmds/status_spec.ts b/spec/cmds/status_spec.ts new file mode 100644 index 00000000..a6236ec6 --- /dev/null +++ b/spec/cmds/status_spec.ts @@ -0,0 +1,87 @@ +import * as path from 'path'; + +import {Logger, WriteTo} from '../../lib/cli/logger'; +import {program} from '../../lib/cmds/update'; +import {Config} from '../../lib/config'; +import {spawnSync} from '../../lib/utils'; + +function getVersions(line: string): string[] { + return line.split(':')[3].split(','); +} + +describe('status', () => { + Logger.writeTo = WriteTo.NONE; + let argv: any; + let tmpDir = path.resolve('selenium_test'); + + // chrome 2.20[last], 2.24 + // geckodriver {{config version}} [last] [default] + // standalone 2.24 [last], {{config version}} [default] + beforeAll((done) => { + Config.osType_ = 'Linux'; + Config.osArch_ = 'x64'; + argv = { + '_': ['update'], + 'versions': {'chrome': '2.24', 'standalone': '2.44.0'}, + 'out_dir': tmpDir + }; + program.run(JSON.parse(JSON.stringify(argv))) + .then(() => { + argv['versions']['chrome'] = '2.20'; + program.run(JSON.parse(JSON.stringify(argv))).then(() => { + done(); + }); + }) + .catch(err => { + done.fail(); + }); + }); + + it('should show the version number of the default and latest versions', () => { + let lines = spawnSync( + process.execPath, + ['built/lib/webdriver.js', 'status', '--out_dir', 'selenium_test'], 'pipe') + .output[1] + .toString() + .split('\n'); + let seleniumLine: string = null; + let chromeLine: string = null; + let geckodriverLine: string = null; + let androidSdkLine: string = null; + let appiumLine: string = null; + + for (let line of lines) { + if (line.indexOf('selenium') >= 0) { + seleniumLine = line; + } else if (line.indexOf('chrome') >= 0) { + chromeLine = line; + } else if (line.indexOf('geckodriver') >= 0) { + geckodriverLine = line; + } else if (line.indexOf('android-sdk') >= 0) { + androidSdkLine = line; + } else if (line.indexOf('appium') >= 0) { + appiumLine = line; + } + } + expect(seleniumLine).not.toBeNull(); + expect(seleniumLine).not.toContain('[default]') + expect(getVersions(seleniumLine).length).toEqual(1); + expect(getVersions(seleniumLine)[0]).toContain('2.44.0 [last]'); + + expect(chromeLine).not.toBeNull(); + expect(chromeLine).not.toContain('[default]'); + expect(getVersions(chromeLine).length).toEqual(2); + expect(getVersions(chromeLine)[0]).toContain('2.20 [last]'); + expect(getVersions(chromeLine)[1]).toContain('2.24'); + + expect(geckodriverLine).not.toBeNull(); + expect(geckodriverLine).toContain('[default]'); + expect(geckodriverLine).toContain('[last]'); + expect(getVersions(geckodriverLine).length).toEqual(1); + + expect(androidSdkLine).not.toBeNull(); + expect(androidSdkLine).toContain('not present'); + expect(appiumLine).not.toBeNull(); + expect(appiumLine).toContain('not present'); + }); +});