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

Commit a451834

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 a451834

File tree

5 files changed

+58
-21
lines changed

5 files changed

+58
-21
lines changed

lib/browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export interface ElementHelper extends Function {
8989
*/
9090
function buildElementHelper(browser: ProtractorBrowser): ElementHelper {
9191
let element = ((locator: Locator) => {
92-
return new ElementArrayFinder(browser).all(locator).toElementFinder_();
93-
}) as ElementHelper;
92+
return new ElementArrayFinder(browser).all(locator).toElementFinder_();
93+
}) as ElementHelper;
9494

9595
element.all = (locator: Locator) => {
9696
return new ElementArrayFinder(browser).all(locator);
@@ -1047,8 +1047,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
10471047
clientSideScripts.setLocation, 'Protractor.setLocation()', rootEl, url)
10481048
.then((browserErr: Error) => {
10491049
if (browserErr) {
1050-
throw 'Error while navigating to \'' + url +
1051-
'\' : ' + JSON.stringify(browserErr);
1050+
throw 'Error while navigating to \'' + url + '\' : ' +
1051+
JSON.stringify(browserErr);
10521052
}
10531053
}));
10541054
}

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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ 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, opt_relativeTo?: string): string[] {
59+
let resolvedFiles: string[] = [];
6160
let cwd = opt_relativeTo || process.cwd();
6261

6362
patterns = (typeof patterns === 'string') ? [patterns] : patterns;
@@ -82,8 +81,8 @@ export class ConfigParser {
8281
*
8382
* @return {Array} An array of globs locating the spec files
8483
*/
85-
static getSpecs(config: Config): Array<string> {
86-
let specs: Array<string> = [];
84+
static getSpecs(config: Config): string[] {
85+
let specs: string[] = [];
8786
if (config.suite) {
8887
config.suite.split(',').forEach((suite) => {
8988
let suiteList = config.suites ? config.suites[suite] : null;
@@ -115,8 +114,9 @@ export class ConfigParser {
115114
private addConfig_(additionalConfig: any, relativeTo: string): void {
116115
// All filepaths should be kept relative to the current config location.
117116
// This will not affect absolute paths.
118-
['seleniumServerJar', 'chromeDriver', 'onPrepare', 'firefoxPath', 'frameworkPath'].forEach(
119-
(name) => {
117+
['seleniumServerJar', 'chromeDriver', 'firefoxPath', 'frameworkPath', 'geckoDriver',
118+
'onPrepare']
119+
.forEach((name: string) => {
120120
if (additionalConfig[name] && typeof additionalConfig[name] === 'string') {
121121
additionalConfig[name] = path.resolve(relativeTo, additionalConfig[name]);
122122
}
@@ -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
/**

lib/driverProviders/sauce.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export class Sauce extends DriverProvider {
6565
this.config_.capabilities['build'] = this.config_.sauceBuild;
6666
let protocol = this.config_.sauceSeleniumUseHttp ? 'http://' : 'https://';
6767
let auth = protocol + this.config_.sauceUser + ':' + this.config_.sauceKey + '@';
68-
this.config_.seleniumAddress = auth +
69-
(this.config_.sauceSeleniumAddress ? this.config_.sauceSeleniumAddress :
70-
'ondemand.saucelabs.com:443/wd/hub');
68+
this.config_.seleniumAddress =
69+
auth + (this.config_.sauceSeleniumAddress ? this.config_.sauceSeleniumAddress :
70+
'ondemand.saucelabs.com:443/wd/hub');
7171

7272
// Append filename to capabilities.name so that it's easier to identify
7373
// tests.

0 commit comments

Comments
 (0)