Skip to content

Commit

Permalink
feat(gecko): Add geckodriver, related config, and flags
Browse files Browse the repository at this point in the history
Users will still need 'marionette': true in their capabilities in order to use gecko driver.
  • Loading branch information
heathkit committed Sep 2, 2016
1 parent 9a4a58e commit 61af7be
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ built/
node_modules/
selenium/
typings/
.idea/
2 changes: 2 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"webdriverVersions": {
"selenium": "2.53.1",
"chromedriver": "2.23",
"geckodriver": "v0.9.0",
"iedriver": "2.53.1",
"androidsdk": "24.4.1",
"appium": "1.5.3"
},
"cdnUrls": {
"selenium": "https://selenium-release.storage.googleapis.com/",
"chromedriver": "https://chromedriver.storage.googleapis.com/",
"geckodriver": "https://github.com/mozilla/geckodriver/releases/download/",
"iedriver": "https://selenium-release.storage.googleapis.com/",
"androidsdk": "http://dl.google.com/android/"
}
Expand Down
52 changes: 52 additions & 0 deletions lib/binaries/gecko_driver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as path from 'path';

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

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

/**
* The gecko driver binary.
*/
export class GeckoDriver extends Binary {
static os = [OS.Windows_NT, OS.Linux, OS.Darwin];
static id = 'gecko';
static versionDefault = Config.binaryVersions().gecko;
static isDefault = true;
static shortName = ['gecko'];

static suffixes: {[key: string]: string} = {
'Darwin': '-mac.tar.gz',
'Linux': '-linux64.tar.gz',
'Windows_NT': '-win64.zip'
};

constructor() {
super();
this.name = 'geckodriver';
this.versionCustom = GeckoDriver.versionDefault;
this.prefixDefault = 'geckodriver-';
this.cdn = Config.cdnUrls().gecko;
}

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

versionDefault(): string { return GeckoDriver.versionDefault; }

suffix(ostype: string, arch: string): string {
if (!GeckoDriver.supports(ostype, arch)) {
throw new Error('GeckoDriver doesn\'t support ${ostype} ${arch}!');
}

return GeckoDriver.suffixes[ostype];
}

static supports(ostype: string, arch: string): boolean {
return arch == 'x64' && (ostype in GeckoDriver.suffixes);
}

url(ostype: string, arch: string): string {
let urlBase = this.cdn + this.version() + '/';
let filename = this.prefix() + this.version() + this.suffix(ostype, arch);
return urlBase + filename;
}
}
1 change: 0 additions & 1 deletion lib/binaries/ie_driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class IEDriver extends Binary {
return '_x64_' + this.versionCustom;
} else {
return '_Win32_' + this.versionCustom;
;
}
}
return '';
Expand Down
1 change: 1 addition & 0 deletions lib/binaries/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './binary';
export * from './chrome_driver';
export * from './gecko_driver';
export * from './ie_driver';
export * from './android_sdk';
export * from './appium';
Expand Down
7 changes: 5 additions & 2 deletions lib/cmds/opts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AndroidSDK, Appium, ChromeDriver, IEDriver, StandAlone} from '../binaries';
import {AndroidSDK, Appium, ChromeDriver, GeckoDriver, IEDriver, StandAlone} from '../binaries';
import {Cli, Option, Options} from '../cli';
import {Config} from '../config';

Expand All @@ -18,6 +18,7 @@ export const GECKO = 'gecko';
export const ANDROID = 'android';
export const IOS = 'ios';
export const VERSIONS_CHROME = 'versions.chrome';
export const VERSIONS_GECKO = 'versions.gecko';
export const VERSIONS_STANDALONE = 'versions.standalone';
export const VERSIONS_IE = 'versions.ie';
export const VERSIONS_ANDROID = 'versions.android';
Expand Down Expand Up @@ -47,16 +48,18 @@ opts[STANDALONE] = new Option(
STANDALONE, 'Install or update selenium standalone', 'boolean', StandAlone.isDefault);
opts[CHROME] =
new Option(CHROME, 'Install or update chromedriver', 'boolean', ChromeDriver.isDefault);
opts[GECKO] = new Option(GECKO, 'Install or update geckodriver', 'boolean', GeckoDriver.isDefault);
opts[IE] = new Option(IE, 'Install or update ie driver', 'boolean', IEDriver.isDefault);
opts[IE32] = new Option(IE32, 'Install or update 32-bit ie driver', 'boolean', IEDriver.isDefault);
opts[EDGE] = new Option(
EDGE, 'Use installed Microsoft Edge driver', 'string',
'C:\\Program Files (x86)\\Microsoft Web Driver\\MicrosoftWebDriver.exe');
opts[GECKO] = new Option(GECKO, 'Use path for gecko driver', 'string');
opts[ANDROID] = new Option(ANDROID, 'Update/use the android sdk', 'boolean', AndroidSDK.isDefault);
opts[IOS] = new Option(IOS, 'Update the iOS sdk', 'boolean', false);
opts[VERSIONS_CHROME] = new Option(
VERSIONS_CHROME, 'Optional chrome driver version', 'string', ChromeDriver.versionDefault);
opts[VERSIONS_GECKO] = new Option(
VERSIONS_GECKO, 'Optional gecko driver version', 'string', GeckoDriver.versionDefault);
opts[VERSIONS_ANDROID] = new Option(
VERSIONS_ANDROID, 'Optional android sdk version', 'string', AndroidSDK.versionDefault);
opts[VERSIONS_STANDALONE] = new Option(
Expand Down
18 changes: 6 additions & 12 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as os from 'os';
import * as path from 'path';

import {AndroidSDK, Appium, Binary, BinaryMap, ChromeDriver, IEDriver, StandAlone} from '../binaries';
import {GeckoDriver} from '../binaries/gecko_driver';
import {Logger, Options, Program} from '../cli';
import {Config} from '../config';
import {FileManager} from '../files';
Expand All @@ -26,7 +27,6 @@ let prog = new Program()
.addOption(Opts[Opt.VERSIONS_ANDROID])
.addOption(Opts[Opt.VERSIONS_APPIUM])
.addOption(Opts[Opt.CHROME_LOGS])
.addOption(Opts[Opt.GECKO])
.addOption(Opts[Opt.LOGGING])
.addOption(Opts[Opt.ANDROID])
.addOption(Opts[Opt.AVDS])
Expand Down Expand Up @@ -133,6 +133,11 @@ function start(options: Options) {
args.push('-Dwebdriver.chrome.logfile=' + chromeLogs);
}
}
if (downloadedBinaries[GeckoDriver.id] != null) {
args.push(
'-Dwebdriver.gecko.driver=' +
path.join(outputDir, binaries[GeckoDriver.id].executableFilename(osType)));
}
if (downloadedBinaries[IEDriver.id] != null) {
if (options[Opt.IE32]) {
binaries[IEDriver.id].arch = 'Win32';
Expand All @@ -153,17 +158,6 @@ function start(options: Options) {
// driver does not exist.
}
}
if (options[Opt.GECKO].getString()) {
let gecko = options[Opt.GECKO].getString();
try {
if (fs.statSync(gecko).isFile()) {
args.push('-Dwebdriver.edge.driver=' + gecko);
}
} catch (err) {
// The file does not exist.
logger.warn('The absolute path provided for gecko (' + gecko + ') does not exist');
}
}
if (options[Opt.ANDROID].getBoolean()) {
if (downloadedBinaries[AndroidSDK.id] != null) {
let avds = options[Opt.AVDS].getString();
Expand Down
14 changes: 13 additions & 1 deletion lib/cmds/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from 'path';
import * as q from 'q';
import * as rimraf from 'rimraf';

import {AndroidSDK, Appium, Binary, ChromeDriver, IEDriver, StandAlone} from '../binaries';
import {AndroidSDK, Appium, Binary, ChromeDriver, GeckoDriver, IEDriver, StandAlone} from '../binaries';
import {Logger, Options, Program} from '../cli';
import {Config} from '../config';
import {Downloader, FileManager} from '../files';
Expand All @@ -31,6 +31,10 @@ let prog = new Program()
.addOption(Opts[Opt.ANDROID_ABIS])
.addOption(Opts[Opt.ANDROID_ACCEPT_LICENSES]);

if (GeckoDriver.supports(os.type(), os.arch())) {
prog.addOption(Opts[Opt.VERSIONS_GECKO]).addOption(Opts[Opt.GECKO]);
}

if (os.type() === 'Darwin') {
prog.addOption(Opts[Opt.IOS]);
}
Expand Down Expand Up @@ -65,6 +69,7 @@ if (argv._[0] === 'update-run') {
function update(options: Options): void {
let standalone = options[Opt.STANDALONE].getBoolean();
let chrome = options[Opt.CHROME].getBoolean();
let gecko = options[Opt.GECKO].getBoolean();
let ie: boolean = false;
let ie32: boolean = false;
if (options[Opt.IE]) {
Expand Down Expand Up @@ -100,6 +105,9 @@ function update(options: Options): void {
if (options[Opt.VERSIONS_IE]) {
binaries[IEDriver.id].versionCustom = options[Opt.VERSIONS_IE].getString();
}
if (options[Opt.VERSIONS_GECKO]) {
binaries[GeckoDriver.id].versionCustom = options[Opt.VERSIONS_GECKO].getString();
}
binaries[AndroidSDK.id].versionCustom = options[Opt.VERSIONS_ANDROID].getString();
binaries[Appium.id].versionCustom = options[Opt.VERSIONS_APPIUM].getString();

Expand All @@ -123,6 +131,10 @@ function update(options: Options): void {
let binary = binaries[ChromeDriver.id];
updateBinary(binary, outputDir, proxy, ignoreSSL);
}
if (gecko) {
let binary = binaries[GeckoDriver.id];
updateBinary(binary, outputDir, proxy, ignoreSSL);
}
if (ie) {
let binary = binaries[IEDriver.id];
binary.arch = os.arch(); // Win32 or x64
Expand Down
3 changes: 3 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let logger = new Logger('config');
export interface ConfigFile {
selenium?: string;
chrome?: string;
gecko?: string;
ie?: string;
android?: string;
appium?: string;
Expand Down Expand Up @@ -53,6 +54,7 @@ export class Config {
let configVersions: ConfigFile = {};
configVersions.selenium = configFile.webdriverVersions.selenium;
configVersions.chrome = configFile.webdriverVersions.chromedriver;
configVersions.gecko = configFile.webdriverVersions.geckodriver;
configVersions.ie = configFile.webdriverVersions.iedriver;
configVersions.android = configFile.webdriverVersions.androidsdk;
configVersions.appium = configFile.webdriverVersions.appium;
Expand All @@ -68,6 +70,7 @@ export class Config {
let configCdnUrls: ConfigFile = {};
configCdnUrls.selenium = configFile.cdnUrls.selenium;
configCdnUrls.chrome = configFile.cdnUrls.chromedriver;
configCdnUrls.gecko = configFile.cdnUrls.geckodriver;
configCdnUrls.ie = configFile.cdnUrls.iedriver;
configCdnUrls.android = configFile.cdnUrls.androidsdk;
return configCdnUrls;
Expand Down
4 changes: 4 additions & 0 deletions lib/files/file_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Binary, BinaryMap, ChromeDriver, IEDriver, AndroidSDK, Appium, StandAlon
import {DownloadedBinary} from './downloaded_binary';
import {Downloader} from './downloader';
import {Logger} from '../cli';
import {GeckoDriver} from '../binaries/gecko_driver';

let logger = new Logger('file_manager');

Expand Down Expand Up @@ -61,6 +62,9 @@ export class FileManager {
if (FileManager.checkOS_(osType, ChromeDriver)) {
binaries[ChromeDriver.id] = new ChromeDriver();
}
if (FileManager.checkOS_(osType, GeckoDriver)) {
binaries[GeckoDriver.id] = new GeckoDriver();
}
if (FileManager.checkOS_(osType, IEDriver)) {
binaries[IEDriver.id] = new IEDriver();
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
"sourceMap": true,
"declaration": true,
"removeComments": false,
"noImplicitAny": true,
Expand Down

0 comments on commit 61af7be

Please sign in to comment.