Skip to content

Commit 9a2a36d

Browse files
committed
chore(bin): binaries separated from webdriver-manager with unit tests
1 parent 1820fbc commit 9a2a36d

31 files changed

+1755
-1
lines changed

.clang-format

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Language: JavaScript
2+
BasedOnStyle: Google
3+
ColumnLimit: 100

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
built/
2+
node_modules/
3+
selenium/
4+
typings/

README.md

+67-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
1-
# webdriver-manager
1+
# webdriver-manager
2+
3+
### Setup
4+
5+
```
6+
npm install
7+
```
8+
9+
### Testing
10+
11+
```
12+
gulp test
13+
```
14+
15+
### Running webdriver
16+
```
17+
node built/lib/webdriver.js <command>
18+
```
19+
20+
```
21+
Usage:webdriver-manager <command> [options]
22+
23+
Commands:
24+
clean removes all downloaded driver files from the out_dir
25+
start start up the selenium server
26+
status list the current available drivers
27+
update install or update selected binaries
28+
29+
Options:
30+
--out_dir Location to output/expect [default: /src/webdriver-manager/selenium]
31+
--seleniumPort Optional port for the selenium standalone server
32+
--versions_standalone Optional seleniuim standalone server version [default: 2.52.0]
33+
--versions_chrome Optional chrome driver version [default: 2.21]
34+
--ignore_ssl Ignore SSL certificates
35+
--proxy Proxy to use for the install or update command
36+
--alternate_cnd Alternate CDN to binaries
37+
--standalone Install or update selenium standalone [default: true]
38+
--chrome Install or update chromedriver [default: true]
39+
```
40+
41+
### Running a specific command
42+
43+
running update
44+
```
45+
node built/lib/cmds/update.js update-run
46+
```
47+
48+
help update
49+
```
50+
node built/lib/cmds/update.js update-help
51+
```
52+
53+
```
54+
Usage: update-run [options]
55+
update-help
56+
Description: install or update selected binaries
57+
58+
Options:
59+
--out_dir Location to output/expect [default: /src/webdriver-manager/selenium]
60+
--ignore_ssl Ignore SSL certificates
61+
--proxy Proxy to use for the install or update command
62+
--alternate_cnd Alternate CDN to binaries
63+
--standalone Install or update selenium standalone [default: true]
64+
--chrome Install or update chromedriver [default: true]
65+
--versions_standalone Optional seleniuim standalone server version [default: 2.52.0]
66+
--versions_chrome Optional chrome driver version [default: 2.21]
67+
```

config.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"webdriverVersions": {
3+
"selenium": "2.52.0",
4+
"chromedriver": "2.21",
5+
"iedriver": "2.52.0"
6+
},
7+
"cdnUrls": {
8+
"selenium": "https://selenium-release.storage.googleapis.com/",
9+
"chromedriver": "https://chromedriver.storage.googleapis.com/",
10+
"iedriver": "https://selenium-release.storage.googleapis.com/"
11+
}
12+
13+
}

gulpfile.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
var clangFormat = require('clang-format');
5+
var gulpFormat = require('gulp-clang-format');
6+
var runSequence = require('run-sequence');
7+
var spawn = require('child_process').spawn;
8+
9+
var runSpawn = function(done, task, opt_arg) {
10+
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
11+
var child = spawn(task, opt_arg, {stdio: 'inherit'});
12+
var running = false;
13+
child.on('close', function() {
14+
if (!running) {
15+
running = true;
16+
done();
17+
}
18+
});
19+
child.on('error', function() {
20+
if (!running) {
21+
console.error('gulp encountered a child error');
22+
running = true;
23+
done();
24+
}
25+
});
26+
};
27+
28+
gulp.task('copy', function() {
29+
return gulp.src(['config.json', 'package.json'])
30+
.pipe(gulp.dest('built/'));
31+
});
32+
33+
gulp.task('clang', function() {
34+
return gulp.src(['src/**/*.ts'])
35+
.pipe(gulpFormat.checkFormat('file', clangFormat))
36+
.on('warning', function(e) {
37+
console.log(e);
38+
});
39+
});
40+
41+
gulp.task('typings', function(done) {
42+
runSpawn(done, 'node', ['node_modules/typings/dist/bin.js', 'install']);
43+
});
44+
45+
gulp.task('tsc', function(done) {
46+
runSpawn(done, 'node', ['node_modules/typescript/bin/tsc']);
47+
});
48+
49+
gulp.task('prepublish', function(done) {
50+
runSequence(['typings', 'clang'], 'tsc', 'copy', done);
51+
});
52+
53+
gulp.task('default',['prepublish']);
54+
gulp.task('build',['prepublish']);
55+
56+
gulp.task('test', ['build'], function(done) {
57+
var opt_arg = [];
58+
opt_arg.push('node_modules/jasmine/bin/jasmine.js');
59+
runSpawn(done, 'node', opt_arg);
60+
});

lib/binaries/binary.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* operating system enum
3+
*/
4+
export enum OS {
5+
Windows_NT,
6+
Linux,
7+
Darwin
8+
}
9+
10+
/**
11+
* Dictionary to map the binary's id to the binary object
12+
*/
13+
export interface BinaryMap<T extends Binary> { [id: string]: T; }
14+
15+
16+
/**
17+
* The binary object base class
18+
*/
19+
export class Binary {
20+
static os: Array<OS>; // the operating systems, the binary can run on
21+
static id: string; // the binaries key identifier
22+
static isDefault: boolean; // to download by default
23+
static versionDefault: string; // a static default version variable
24+
static shortName: Array<string>; // the names used for a binary download
25+
name: string; // used for logging to console
26+
prefixDefault: string; // start of the file name
27+
versionCustom: string; // version of file
28+
suffixDefault: string; // file type for downloading
29+
cdn: string; // url protocol and host
30+
31+
/**
32+
* @param ostype The operating system.
33+
* @returns The executable file type.
34+
*/
35+
executableSuffix(ostype: string): string {
36+
if (ostype == 'Windows_NT') {
37+
return '.exe';
38+
} else {
39+
return '';
40+
}
41+
}
42+
43+
/**
44+
* @param ostype The operating system.
45+
* @returns The file name for the executable.
46+
*/
47+
executableFilename(ostype: string): string {
48+
return this.prefix() + this.version() + this.executableSuffix(ostype);
49+
}
50+
51+
prefix(): string { return this.prefixDefault; }
52+
53+
version(): string { return this.versionCustom; }
54+
55+
suffix(ostype?: string, arch?: string): string { return this.suffixDefault; }
56+
57+
filename(ostype?: string, arch?: string): string { return this.prefix() + this.version() + this.suffix(ostype, arch); }
58+
59+
shortVersion(version: string): string { return version.slice(0, version.lastIndexOf('.')); }
60+
61+
/**
62+
* A base class method that should be overridden.
63+
*/
64+
id(): string { return 'not implemented'; }
65+
66+
/**
67+
* A base class method that should be overridden.
68+
*/
69+
versionDefault(): string { return 'not implemented'; }
70+
71+
/**
72+
* A base class method that should be overridden.
73+
*/
74+
url(ostype?: string, arch?: string): string { return 'not implemented'; }
75+
}

lib/binaries/chromeDriver.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {arch, type} from 'os';
2+
3+
import {Binary, OS} from './binary';
4+
import {Config} from '../config';
5+
6+
/**
7+
* The chrome driver binary.
8+
*/
9+
export class ChromeDriver extends Binary {
10+
static os = [OS.Windows_NT, OS.Linux, OS.Darwin];
11+
static id = 'chrome';
12+
static versionDefault = Config.binaryVersions().chrome;
13+
static isDefault = true;
14+
static shortName = ['chrome'];
15+
16+
constructor() {
17+
super();
18+
this.name = 'chromedriver';
19+
this.versionCustom = ChromeDriver.versionDefault;
20+
this.prefixDefault = 'chromedriver_';
21+
this.suffixDefault = '.zip';
22+
this.cdn = Config.cdnUrls().chrome;
23+
}
24+
25+
id(): string { return ChromeDriver.id; }
26+
27+
versionDefault(): string { return ChromeDriver.versionDefault; }
28+
29+
suffix(ostype: string, arch: string): string {
30+
if (ostype === 'Darwin') {
31+
return 'mac32' + this.suffixDefault;
32+
} else if (ostype === 'Linux') {
33+
if (arch === 'x64') {
34+
return 'linux64' + this.suffixDefault;
35+
} else {
36+
return 'linux32' + this.suffixDefault;
37+
}
38+
} else if (ostype === 'Windows_NT') {
39+
return 'win32' + this.suffixDefault;
40+
}
41+
}
42+
43+
url(ostype: string, arch: string): string {
44+
let urlBase = this.cdn + this.version() + '/';
45+
let filename = this.prefix() + this.suffix(ostype, arch);
46+
return urlBase + filename;
47+
}
48+
}

lib/binaries/ieDriver.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {arch, type} from 'os';
2+
3+
import {Binary, OS} from './binary';
4+
import {Config} from '../config';
5+
6+
/**
7+
* The internet explorer binary.
8+
*/
9+
export class IEDriver extends Binary {
10+
static os = [OS.Windows_NT];
11+
static id = 'ie';
12+
static versionDefault = Config.binaryVersions().ie;
13+
static isDefault = false;
14+
static shortName = ['ie', 'ie32'];
15+
16+
constructor() {
17+
super();
18+
this.name = 'IEDriver';
19+
this.versionCustom = IEDriver.versionDefault;
20+
this.prefixDefault = 'IEDriverServer';
21+
this.suffixDefault = '.zip';
22+
this.cdn = Config.cdnUrls().ie;
23+
}
24+
25+
id(): string { return IEDriver.id; }
26+
27+
versionDefault(): string { return IEDriver.versionDefault; }
28+
29+
version(): string {
30+
if (type() == 'Windows_NT') {
31+
if (arch() == 'x64') {
32+
return '_x64_' + this.versionCustom;
33+
} else {
34+
return '_Win32_' + this.versionCustom;
35+
;
36+
}
37+
}
38+
return '';
39+
}
40+
41+
url(): string {
42+
let urlBase = this.cdn + this.shortVersion(this.version()) + '/';
43+
let filename = this.prefix() + this.version() + this.suffix();
44+
return urlBase + filename;
45+
}
46+
}

lib/binaries/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './binary';
2+
export * from './chromeDriver';
3+
export * from './ieDriver';
4+
export * from './standAlone';

lib/binaries/standAlone.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Binary, OS} from './binary';
2+
import {Config} from '../config';
3+
4+
/**
5+
* The selenium server jar.
6+
*/
7+
export class StandAlone extends Binary {
8+
static os = [OS.Windows_NT, OS.Linux, OS.Darwin];
9+
static id = 'standalone';
10+
static versionDefault = Config.binaryVersions().selenium;
11+
static isDefault = true;
12+
static shortName = ['standalone'];
13+
14+
constructor() {
15+
super();
16+
this.name = 'selenium standalone';
17+
this.versionCustom = StandAlone.versionDefault;
18+
this.prefixDefault = 'selenium-server-standalone-';
19+
this.suffixDefault = '.jar';
20+
this.cdn = Config.cdnUrls().selenium;
21+
}
22+
23+
id(): string { return StandAlone.id; }
24+
25+
versionDefault(): string { return StandAlone.versionDefault; }
26+
27+
url(): string {
28+
let urlBase = this.cdn + this.shortVersion(this.version()) + '/';
29+
let filename = this.prefix() + this.version() + this.suffix();
30+
return urlBase + filename;
31+
}
32+
33+
executableSuffix(ostype?: string): string { return '.jar'; }
34+
}

0 commit comments

Comments
 (0)