Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 06718e8

Browse files
committed
fix(local): allow local driver provider to use gecko driver from config
- Add gecko driver as configuration option to be used in the local driver provider. - Nit fixes to use string[] over Array<string> in the configParser.ts - Add functionality to addDefaultBinaryLocs_ to use the geckoDriver value set in the config or to check locally in the webdriver-manager/selenium folder closes #4408 and closes #4411.
1 parent c0b8770 commit 06718e8

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

lib/config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,22 @@ export interface Config {
6666
jvmArgs?: string[];
6767
};
6868
/**
69-
* ChromeDriver location is used to help find the chromedriver binary.
70-
* This will be passed to the Selenium jar as the system property
71-
* webdriver.chrome.driver. If null, Selenium will attempt to find
72-
* ChromeDriver using PATH.
69+
* ChromeDriver location is used to help find the chromedriver binary. This will be passed to the
70+
* Selenium jar as the system property webdriver.chrome.driver. If the value is not set when
71+
* launching locally, it will use the default values downloaded from webdriver-manager.
7372
*
7473
* example:
7574
* chromeDriver: './node_modules/webdriver-manager/selenium/chromedriver_2.20'
7675
*/
7776
chromeDriver?: string;
7877

78+
/**
79+
* geckoDriver location is used to help find the gecko binary. This will be passed to the Selenium
80+
* jar as the system property webdriver.gecko.driver. If the value is not set when launching
81+
* locally, it will use the default values downloaded from webdriver-manager.
82+
*/
83+
geckoDriver?: string;
84+
7985
// ---- 2. To connect to a Selenium Server which is already running ----------
8086

8187
/**

lib/configParser.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class ConfigParser {
5555
* @return {Array} The resolved file paths.
5656
*/
5757
public static resolveFilePatterns(
58-
patterns: Array<string>|string, opt_omitWarnings?: boolean,
59-
opt_relativeTo?: string): Array<string> {
60-
let resolvedFiles: Array<string> = [];
58+
patterns: string[]|string, opt_omitWarnings?: boolean,
59+
opt_relativeTo?: string): string[] {
60+
let resolvedFiles: string[] = [];
6161
let cwd = opt_relativeTo || process.cwd();
6262

6363
patterns = (typeof patterns === 'string') ? [patterns] : patterns;
@@ -82,8 +82,8 @@ export class ConfigParser {
8282
*
8383
* @return {Array} An array of globs locating the spec files
8484
*/
85-
static getSpecs(config: Config): Array<string> {
86-
let specs: Array<string> = [];
85+
static getSpecs(config: Config): string[] {
86+
let specs: string[] = [];
8787
if (config.suite) {
8888
config.suite.split(',').forEach((suite) => {
8989
let suiteList = config.suites ? config.suites[suite] : null;
@@ -115,12 +115,12 @@ export class ConfigParser {
115115
private addConfig_(additionalConfig: any, relativeTo: string): void {
116116
// All filepaths should be kept relative to the current config location.
117117
// This will not affect absolute paths.
118-
['seleniumServerJar', 'chromeDriver', 'onPrepare', 'firefoxPath', 'frameworkPath'].forEach(
119-
(name) => {
120-
if (additionalConfig[name] && typeof additionalConfig[name] === 'string') {
121-
additionalConfig[name] = path.resolve(relativeTo, additionalConfig[name]);
122-
}
123-
});
118+
['seleniumServerJar', 'chromeDriver', 'firefoxPath', 'frameworkPath',
119+
'geckoDriver', 'onPrepare'].forEach((name: string) => {
120+
if (additionalConfig[name] && typeof additionalConfig[name] === 'string') {
121+
additionalConfig[name] = path.resolve(relativeTo, additionalConfig[name]);
122+
}
123+
});
124124

125125
merge_(this.config_, additionalConfig);
126126
}
@@ -206,10 +206,10 @@ let makeArray = function(item: any): any {
206206
* Adds to an array all the elements in another array without adding any
207207
* duplicates
208208
*
209-
* @param {Array<string>} dest The array to add to
210-
* @param {Array<string>} src The array to copy from
209+
* @param {string[]} dest The array to add to
210+
* @param {string[]} src The array to copy from
211211
*/
212-
let union = function(dest: Array<string>, src: Array<string>): void {
212+
let union = function(dest: string[], src: string[]): void {
213213
let elems: any = {};
214214
for (let key in dest) {
215215
elems[dest[key]] = true;

lib/driverProviders/local.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,37 @@ export class Local extends DriverProvider {
8686
}
8787
}
8888
}
89+
90+
if (this.config_.capabilities.browserName === 'firefox') {
91+
if (!this.config_.geckoDriver) {
92+
logger.debug(
93+
'Attempting to find the gecko driver binary in the default ' +
94+
'location used by webdriver-manager');
95+
96+
try {
97+
let updateJson = path.resolve(SeleniumConfig.getSeleniumDir(), 'update-config.json');
98+
let updateConfig = JSON.parse(fs.readFileSync(updateJson).toString());
99+
this.config_.geckoDriver = updateConfig.gecko.last;
100+
} catch (err) {
101+
throw new BrowserError(
102+
logger,
103+
'No update-config.json found. ' +
104+
'Run \'webdriver-manager update\' to download binaries.');
105+
}
106+
}
107+
108+
// Check if file exists, if not try .exe or fail accordingly
109+
if (!fs.existsSync(this.config_.geckoDriver)) {
110+
if (fs.existsSync(this.config_.geckoDriver + '.exe')) {
111+
this.config_.geckoDriver += '.exe';
112+
} else {
113+
throw new BrowserError(
114+
logger,
115+
'Could not find gecko driver at ' + this.config_.geckoDriver +
116+
'. Run \'webdriver-manager update\' to download binaries.');
117+
}
118+
}
119+
}
89120
}
90121

91122
/**

0 commit comments

Comments
 (0)