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

Commit a69ebc3

Browse files
committed
feat(runner): use selenium and chromedriver from the default location if nothing else is specified
1 parent f54fd5d commit a69ebc3

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

lib/runner.js

+44-23
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ var setUpSelenium = function() {
120120
});
121121
}
122122

123+
var defaultChromedriver;
124+
if (config.chromeDriver) {
125+
if (!fs.existsSync(config.chromeDriver)) {
126+
if (fs.existsSync(config.chromeDriver + '.exe')) {
127+
config.chromeDriver += '.exe';
128+
} else {
129+
throw 'Could not find chromedriver at ' + config.chromeDriver;
130+
}
131+
}
132+
} else {
133+
defaultChromedriver = path.resolve(__dirname,
134+
'../selenium/chromedriver');
135+
if (fs.existsSync(defaultChromedriver)) {
136+
config.chromeDriver = defaultChromedriver;
137+
} else if (fs.existsSync(defaultChromedriver + '.exe')) {
138+
config.chromeDriver = defaultChromedriver + '.exe';
139+
}
140+
}
141+
142+
// Priority
143+
// 1) if chromeOnly, use that
144+
// 2) if seleniumAddress is given, use that
145+
// 3) if a sauceAccount is given, use that.
146+
// 4) if a seleniumServerJar is specified, use that
147+
// 5) try to find the seleniumServerJar in protractor/selenium
123148
if (config.chromeOnly) {
124149
util.puts('Using ChromeDriver directly...');
125150
deferred.fulfill(null);
@@ -137,23 +162,29 @@ var setUpSelenium = function() {
137162

138163
util.puts('Using SauceLabs selenium server at ' + config.seleniumAddress);
139164
deferred.fulfill(config.seleniumAddress);
140-
} else if (config.seleniumServerJar) {
165+
} else {
141166
util.puts('Starting selenium standalone server...');
142-
if (config.chromeDriver) {
143-
if (!fs.existsSync(config.chromeDriver)) {
144-
if (fs.existsSync(config.chromeDriver + '.exe')) {
145-
config.chromeDriver += '.exe';
146-
} else {
147-
throw 'Could not find chromedriver at ' + config.chromeDriver;
148-
}
167+
168+
if (!config.seleniumServerJar) {
169+
// Try to use the default location.
170+
var defaultStandalone = path.resolve(__dirname,
171+
'../selenium/selenium-server-standalone-' +
172+
require('../package.json').webdriverVersions.selenium + '.jar');
173+
if (!fs.existsSync(defaultStandalone)) {
174+
throw new Error('Unable to start selenium. ' +
175+
'You must specify either a seleniumAddress, ' +
176+
'seleniumServerJar, or saucelabs account, or use webdriver-manager.');
177+
} else {
178+
config.seleniumServerJar = defaultStandalone;
149179
}
150-
config.seleniumArgs.push(
151-
'-Dwebdriver.chrome.driver=' + config.chromeDriver);
180+
} else if (!fs.existsSync(config.seleniumServerJar)) {
181+
throw new Error('there\'s no selenium server jar at the specified '+
182+
'location. Do you have the correct version?');
152183
}
153184

154-
if (config.seleniumServerJar && !fs.existsSync(config.seleniumServerJar)) {
155-
throw new Error('there\'s no selenium server jar at the specified location.'+
156-
'Do you have the correct version?');
185+
if (config.chromeDriver) {
186+
config.seleniumArgs.push(
187+
'-Dwebdriver.chrome.driver=' + config.chromeDriver);
157188
}
158189

159190
server = new remote.SeleniumServer(config.seleniumServerJar, {
@@ -166,9 +197,6 @@ var setUpSelenium = function() {
166197
config.seleniumAddress = server.address();
167198
deferred.fulfill(config.seleniumAddress);
168199
});
169-
} else {
170-
throw new Error('You must specify either a seleniumAddress, ' +
171-
'seleniumServerJar, or saucelabs account.');
172200
}
173201

174202
return deferred.promise;
@@ -210,13 +238,6 @@ var runJasmineTests = function() {
210238
var runDeferred = webdriver.promise.defer();
211239

212240
if (config.chromeOnly) {
213-
if (!fs.existsSync(config.chromeDriver)) {
214-
if (fs.existsSync(config.chromeDriver + '.exe')) {
215-
config.chromeDriver += '.exe';
216-
} else {
217-
throw 'Could not find chromedriver at ' + config.chromeDriver;
218-
}
219-
}
220241
var service = new chrome.ServiceBuilder(config.chromeDriver).build();
221242
driver = chrome.createDriver(
222243
new webdriver.Capabilities(config.capabilities), service);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"bin": {
3434
"protractor": "bin/protractor",
35-
"manage-webdriver": "bin/webdriver-manager"
35+
"webdriver-manager": "bin/webdriver-manager"
3636
},
3737
"main": "lib/protractor.js",
3838
"scripts": {

referenceConf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ exports.config = {
1515
// chromeDriver)
1616

1717
// The location of the selenium standalone server .jar file, relative
18-
// to the location of this config.
18+
// to the location of this config. If no other method of starting selenium
19+
// is found, this will default to protractor/selenium/selenium-server...
1920
seleniumServerJar: './selenium/selenium-server-standalone-2.37.0.jar',
2021
// The port to start the selenium server on, or null if the server should
2122
// find its own unused port.

0 commit comments

Comments
 (0)