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

Commit

Permalink
feat(runner): use selenium and chromedriver from the default location…
Browse files Browse the repository at this point in the history
… if nothing else is specified
  • Loading branch information
juliemr committed Nov 28, 2013
1 parent f54fd5d commit a69ebc3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
67 changes: 44 additions & 23 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,31 @@ var setUpSelenium = function() {
});
}

var defaultChromedriver;
if (config.chromeDriver) {
if (!fs.existsSync(config.chromeDriver)) {
if (fs.existsSync(config.chromeDriver + '.exe')) {
config.chromeDriver += '.exe';
} else {
throw 'Could not find chromedriver at ' + config.chromeDriver;
}
}
} else {
defaultChromedriver = path.resolve(__dirname,
'../selenium/chromedriver');
if (fs.existsSync(defaultChromedriver)) {
config.chromeDriver = defaultChromedriver;
} else if (fs.existsSync(defaultChromedriver + '.exe')) {
config.chromeDriver = defaultChromedriver + '.exe';
}
}

// Priority
// 1) if chromeOnly, use that
// 2) if seleniumAddress is given, use that
// 3) if a sauceAccount is given, use that.
// 4) if a seleniumServerJar is specified, use that
// 5) try to find the seleniumServerJar in protractor/selenium
if (config.chromeOnly) {
util.puts('Using ChromeDriver directly...');
deferred.fulfill(null);
Expand All @@ -137,23 +162,29 @@ var setUpSelenium = function() {

util.puts('Using SauceLabs selenium server at ' + config.seleniumAddress);
deferred.fulfill(config.seleniumAddress);
} else if (config.seleniumServerJar) {
} else {
util.puts('Starting selenium standalone server...');
if (config.chromeDriver) {
if (!fs.existsSync(config.chromeDriver)) {
if (fs.existsSync(config.chromeDriver + '.exe')) {
config.chromeDriver += '.exe';
} else {
throw 'Could not find chromedriver at ' + config.chromeDriver;
}

if (!config.seleniumServerJar) {
// Try to use the default location.
var defaultStandalone = path.resolve(__dirname,
'../selenium/selenium-server-standalone-' +
require('../package.json').webdriverVersions.selenium + '.jar');
if (!fs.existsSync(defaultStandalone)) {
throw new Error('Unable to start selenium. ' +
'You must specify either a seleniumAddress, ' +
'seleniumServerJar, or saucelabs account, or use webdriver-manager.');
} else {
config.seleniumServerJar = defaultStandalone;
}
config.seleniumArgs.push(
'-Dwebdriver.chrome.driver=' + config.chromeDriver);
} else if (!fs.existsSync(config.seleniumServerJar)) {
throw new Error('there\'s no selenium server jar at the specified '+
'location. Do you have the correct version?');
}

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

server = new remote.SeleniumServer(config.seleniumServerJar, {
Expand All @@ -166,9 +197,6 @@ var setUpSelenium = function() {
config.seleniumAddress = server.address();
deferred.fulfill(config.seleniumAddress);
});
} else {
throw new Error('You must specify either a seleniumAddress, ' +
'seleniumServerJar, or saucelabs account.');
}

return deferred.promise;
Expand Down Expand Up @@ -210,13 +238,6 @@ var runJasmineTests = function() {
var runDeferred = webdriver.promise.defer();

if (config.chromeOnly) {
if (!fs.existsSync(config.chromeDriver)) {
if (fs.existsSync(config.chromeDriver + '.exe')) {
config.chromeDriver += '.exe';
} else {
throw 'Could not find chromedriver at ' + config.chromeDriver;
}
}
var service = new chrome.ServiceBuilder(config.chromeDriver).build();
driver = chrome.createDriver(
new webdriver.Capabilities(config.capabilities), service);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"bin": {
"protractor": "bin/protractor",
"manage-webdriver": "bin/webdriver-manager"
"webdriver-manager": "bin/webdriver-manager"
},
"main": "lib/protractor.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ exports.config = {
// chromeDriver)

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

0 comments on commit a69ebc3

Please sign in to comment.