Skip to content

Commit

Permalink
chore(latest): get the latest version from the cdn (#198)
Browse files Browse the repository at this point in the history
This reads the xml from the CDN to get the latest chromedriver, iedriver,
or standalone version if the version is 'latest'. If the release is from
Github, use the Github API to get the releases. Also store the downloaded
information to a cache in the output directory (default: selenium/). If
the file is older than one hour it will be rewritten.

When getting the status, we are no longer showing the default version.
Default versions will be deprecated and will be removed from the config.json
file.

When starting the standalone server, use the 'latest' version by default
unless specified by --versions.{binary} flag.

Change the gulp update task to use 3.0.0-beta4 so Firefox tests will pass.
  • Loading branch information
cnishina committed Jan 31, 2017
1 parent c30763c commit fe309ef
Show file tree
Hide file tree
Showing 40 changed files with 1,600 additions and 648 deletions.
4 changes: 2 additions & 2 deletions e2e_spec/desktop_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ describe('desktop browser smoke tests', () => {
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities({browserName: browserName})
.build();
driver.get('http://localhost:4444/selenium-server/driver/?cmd=getLogMessages')
driver.get('http://localhost:4444/wd/hub/status')
.then(() => {
return driver.getPageSource();
})
.then((source: string) => {
expect(source).toContain('OK');
expect(source).toContain('"state":"success"');
return driver.quit();
})
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions e2e_spec/server_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as http from 'http';

describe('sever smoke tests', () => {
it('should be able to ping selenium server', (done) => {
http.get('http://localhost:4444/selenium-server/driver/?cmd=getLogMessages', (resp) => {
http.get('http://localhost:4444/wd/hub/status', (resp) => {
expect(resp.statusCode).toBe(200);
let logs = '';
resp.on('data', (chunk) => logs += chunk);
resp.on('end', () => {
expect(logs).toContain('OK');
expect(logs).toContain('"state":"success"');
done()
});
});
Expand Down
5 changes: 3 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ gulp.task('test:unit', ['format', 'build'], function(done) {
var e2e_env = {headless: false, kvm: true};
gulp.task('update', ['build'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'update', '--android',
'--android-accept-licenses'], done);
'--android-accept-licenses', '--versions.standalone', '3.0.0-beta4'], done);
});
gulp.task('start', ['build', 'shutdown'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'start', '--detach', '--seleniumPort',
'4444', '--android', '--appium-port', '4723', '--quiet'].concat(e2e_env.headless ||
'4444', '--android', '--appium-port', '4723', '--versions.standalone', '3.0.0-beta4',
'--quiet'].concat(e2e_env.headless ||
!e2e_env.kvm ? ['--avds', 'none'] : []), done);
});
gulp.task('shutdown', ['build'], function(done) {
Expand Down
40 changes: 23 additions & 17 deletions lib/binaries/android_sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as rimraf from 'rimraf';
import {Config} from '../config';
import {spawnSync} from '../utils';

import {Binary, OS} from './binary';
import {Binary, BinaryUrl, OS} from './binary';

function getAndroidArch(): string {
switch (Config.osArch()) {
Expand Down Expand Up @@ -49,38 +49,44 @@ export class AndroidSDK extends Binary {

this.name = 'android-sdk';
this.versionCustom = AndroidSDK.versionDefault;
this.prefixDefault = 'android-sdk_r';
this.suffixDefault = '.zip';
}

id(): string {
return AndroidSDK.id;
}

versionDefault(): string {
return AndroidSDK.versionDefault;
prefix(): string {
return 'android-sdk_r';
}

suffix(ostype: string): string {
if (ostype === 'Darwin') {
return '-macosx' + this.suffixDefault;
} else if (ostype === 'Linux') {
suffix(): string {
if (this.ostype === 'Darwin') {
return '-macosx.zip';
} else if (this.ostype === 'Linux') {
return '-linux.tgz';
} else if (ostype === 'Windows_NT') {
return '-windows' + this.suffixDefault;
} else if (this.ostype === 'Windows_NT') {
return '-windows.zip';
}
}

getUrl(): Promise<BinaryUrl> {
return Promise.resolve({url: this.cdn + this.filename(), version: this.versionCustom});
}

getVersionList(): Promise<string[]> {
return null;
}

url(ostype: string): string {
return this.cdn + this.filename(ostype);
return this.cdn + this.filename();
}

zipContentName(ostype: string): string {
if (ostype === 'Darwin') {
zipContentName(): string {
if (this.ostype === 'Darwin') {
return this.name + '-macosx';
} else if (ostype === 'Linux') {
} else if (this.ostype === 'Linux') {
return this.name + '-linux';
} else if (ostype === 'Windows_NT') {
} else if (this.ostype === 'Windows_NT') {
return this.name + '-windows';
}
}
Expand All @@ -92,7 +98,7 @@ export class AndroidSDK extends Binary {
remove(sdkPath: string): void {
try {
let avds = <string[]>require(path.resolve(sdkPath, 'available_avds.json'));
let version = path.basename(sdkPath).slice(this.prefixDefault.length);
let version = path.basename(sdkPath).slice(this.prefix().length);
avds.forEach((avd: string) => {
spawnSync(
path.resolve(sdkPath, 'tools', 'android'),
Expand Down
21 changes: 15 additions & 6 deletions lib/binaries/appium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as rimraf from 'rimraf';

import {Config} from '../config';

import {Binary, OS} from './binary';
import {Binary, BinaryUrl, OS} from './binary';


/**
Expand All @@ -17,25 +17,34 @@ export class Appium extends Binary {

constructor(alternateCDN?: string) {
super(alternateCDN || Config.cdnUrls().appium);

this.name = 'appium';
this.versionCustom = Appium.versionDefault;
this.prefixDefault = 'appium-';
this.suffixDefault = '';
}

id(): string {
return Appium.id;
}

versionDefault(): string {
return Appium.versionDefault;
prefix(): string {
return 'appium-';
}

suffix(): string {
return '';
}

executableSuffix(): string {
return '';
}

getUrl(version?: string): Promise<BinaryUrl> {
return Promise.resolve({url: '', version: this.versionCustom});
}

getVersionList(): Promise<string[]> {
return null;
}

remove(sdkPath: string): void {
rimraf.sync(sdkPath);
}
Expand Down
124 changes: 66 additions & 58 deletions lib/binaries/binary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as fs from 'fs';
import {Config} from '../config';
import {ConfigSource} from './config_source';

/**
* operating system enum
Expand All @@ -9,103 +11,109 @@ export enum OS {
Darwin
}

export interface BinaryUrl {
url: string;
version: string;
}

/**
* Dictionary to map the binary's id to the binary object
*/
export interface BinaryMap<T extends Binary> { [id: string]: T; }

export abstract class Binary {
static os: OS[];

/**
* The binary object base class
*/
export class Binary {
static os: OS[]; // the operating systems, the binary can run on
static id: string; // the binaries key identifier
static versionDefault: string; // a static default version variable
name: string; // used for logging to console
prefixDefault: string; // start of the file name
versionCustom: string; // version of file
suffixDefault: string; // file type for downloading
cdn: string; // url protocol and host
arch: string;

constructor(cdn?: string) {
this.cdn = cdn;
configSource: ConfigSource;

ostype: string = Config.osType();
osarch: string = Config.osArch();

// TODO(cnishina): downloading the latest requires parsing XML or JSON that is assumed to be
// published and formatted in a specific way. If this is not available, let the user download
// the file from an alternative download URL.
alternativeDownloadUrl: string;

cdn: string; // The url host for XML reading or the base path to the url.
opt_ignoreSSL: boolean; // An optional ignore ssl.
opt_proxy: string // An optional proxy.

name: string;
versionDefault: string;
versionCustom: string;

constructor(opt_alternativeCdn?: string) {
this.cdn = opt_alternativeCdn;
}

/**
* @param ostype The operating system.
* @returns The executable file type.
*/
executableSuffix(ostype: string): string {
if (ostype == 'Windows_NT') {
abstract prefix(): string;
abstract suffix(): string;

executableSuffix(): string {
if (this.ostype == 'Windows_NT') {
return '.exe';
} else {
return '';
}
}

/**
* @param ostype The operating system.
* @returns The file name for the executable.
*/
executableFilename(ostype: string): string {
return this.prefix() + this.version() + this.executableSuffix(ostype);
}

prefix(): string {
return this.prefixDefault;
}

version(): string {
return this.versionCustom;
}

suffix(ostype?: string, arch?: string): string {
return this.suffixDefault;
}

filename(ostype?: string, arch?: string): string {
return this.prefix() + this.version() + this.suffix(ostype, arch);
filename(): string {
return this.prefix() + this.version() + this.suffix();
}

/**
* @param ostype The operating system.
* @returns The file name for the file inside the downloaded zip file
* @returns The file name for the executable.
*/
zipContentName(ostype: string): string {
return this.name + this.executableSuffix(ostype);
}

shortVersion(version: string): string {
return version.slice(0, version.lastIndexOf('.'));
executableFilename(): string {
return this.prefix() + this.version() + this.executableSuffix();
}

/**
* A base class method that should be overridden.
* Gets the id of the binary.
*/
id(): string {
return 'not implemented';
}
abstract id(): string;

/**
* A base class method that should be overridden.
* Gets the url to download the file set by the version. This will use the XML if available.
* If not, it will download from an existing url.
*/
versionDefault(): string {
return 'not implemented';
getUrl(version?: string): Promise<BinaryUrl> {
if (this.alternativeDownloadUrl != null) {
return Promise.resolve({url: '', version: ''});
} else {
return this.getVersionList().then(() => {
version = version || Config.binaryVersions()[this.id()];
return this.configSource.getUrl(version).then(binaryUrl => {
this.versionCustom = binaryUrl.version;
return {url: binaryUrl.url, version: binaryUrl.version};
});
});
}
}

/**
* A base class method that should be overridden.
* Gets the list of available versions available based on the xml. If no XML exists, return an
* empty list.
*/
url(ostype?: string, arch?: string): string {
return 'not implemented';
}
abstract getVersionList(): Promise<string[]>;

/**
* Delete an instance of this binary from the file system
*/
remove(filename: string): void {
fs.unlinkSync(filename);
}

/**
* @param ostype The operating system.
* @returns The file name for the file inside the downloaded zip file
*/
zipContentName(): string {
return this.name + this.executableSuffix();
}
}

0 comments on commit fe309ef

Please sign in to comment.