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

Commit

Permalink
feat(troubleshoot): Add more information when the --troubleshoot flag…
Browse files Browse the repository at this point in the history
… is used

Improve error messages and add debug info when
 - the configuration file cannot be parsed
 - a webdriver session cannot be started
 - more than one element is found using `element`

Unify format used for warnings and errors.
  • Loading branch information
juliemr committed Dec 4, 2014
1 parent 7f15570 commit 8b5ae8b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
25 changes: 17 additions & 8 deletions lib/configParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ConfigParser.resolveFilePatterns =
for (var i = 0; i < patterns.length; ++i) {
var matches = glob.sync(patterns[i], {cwd: cwd});
if (!matches.length && !opt_omitWarnings) {
log.puts('Warning: pattern ' + patterns[i] + ' did not match any files.');
log.warn('pattern ' + patterns[i] + ' did not match any files.');
}
for (var j = 0; j < matches.length; ++j) {
resolvedFiles.push(path.resolve(cwd, matches[j]));
Expand Down Expand Up @@ -164,7 +164,7 @@ ConfigParser.prototype.addConfig_ = function(additionalConfig, relativeTo) {

// chromeOnly is deprecated, use directConnect instead.
if (additionalConfig.chromeOnly) {
log.puts('Warning: chromeOnly is deprecated. Use directConnect');
log.warn('chromeOnly is deprecated. Use directConnect');
additionalConfig.directConnect = true;
}
merge_(this.config_, additionalConfig);
Expand All @@ -177,13 +177,22 @@ ConfigParser.prototype.addConfig_ = function(additionalConfig, relativeTo) {
* @param {String} filename
*/
ConfigParser.prototype.addFileConfig = function(filename) {
if (!filename) {
return this;
try {
if (!filename) {
return this;
}
var filePath = path.resolve(process.cwd(), filename);
var fileConfig = require(filePath).config;
if (!fileConfig) {
log.error('configuration file ' + filename + ' did not export a config ' +
'object');
}
fileConfig.configDir = path.dirname(filePath);
this.addConfig_(fileConfig, fileConfig.configDir);
} catch (e) {
log.error('failed loading configuration file ' + filename);
throw e;
}
var filePath = path.resolve(process.cwd(), filename);
var fileConfig = require(filePath).config;
fileConfig.configDir = path.dirname(filePath);
this.addConfig_(fileConfig, fileConfig.configDir);
return this;
};

Expand Down
3 changes: 3 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ var init = function(configFile, additionalConfig) {
}
var config = configParser.getConfig();
log.set(config);
log.debug('Running with --troubleshoot');
log.debug('Protractor version: ' + require('../package.json').version);
log.debug('Your base url for tests is ' + config.baseUrl);
var scheduler = new TaskScheduler(config);

process.on('exit', function(code) {
Expand Down
12 changes: 11 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ var puts = function() {

var debug = function(msg) {
if (troubleshoot) {
puts(msg);
puts('DEBUG - ' + msg);
}
};

var warn = function(msg) {
puts('WARNING - ' + msg);
}

var error = function(msg) {
puts('ERROR - ' + msg);
}

exports.set = set;
exports.print = print;
exports.puts = puts;
exports.debug = debug;
exports.warn = warn;
exports.error = error;
4 changes: 2 additions & 2 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,9 @@ var buildElementHelper = function(ptor) {
elementArrayFinder.locator_.toString());
} else {
if (webElements.length > 1) {
log.puts('warning: more than one element found for locator ' +
log.warn('more than one element found for locator ' +
elementArrayFinder.locator_.toString() +
' - you may need to be more specific');
' - the first result will be used');
}
return [webElements[0]];
}
Expand Down
7 changes: 7 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ Runner.prototype.run = function() {
}).then(function() {
var browser = self.createBrowser();
self.setupGlobals_(browser);
return browser.getSession().then(function(session) {
log.debug('WebDriver session successfully started with capabilities ' +
util.inspect(session.getCapabilities()));
}, function(err) {
log.error('Unable to start a WebDriver session.');
throw err;
});
// 3) Setup plugins
}).then(function() {
plugins = new Plugins(self.config_);
Expand Down
7 changes: 4 additions & 3 deletions lib/taskScheduler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* The taskScheduler keeps track of the specs that needs to run next
* The taskScheduler keeps track of the spec files that needs to run next
* and which task is running what.
*/
'use strict';
Expand Down Expand Up @@ -34,8 +34,9 @@ var TaskScheduler = function(config) {

if (config.capabilities) {
if (config.multiCapabilities.length) {
log.puts('Running using config.multiCapabilities - ' +
'config.capabilities will be ignored');
log.warn('You have specified both capabilites and ' +
'multiCapabilities. This will result in capabilities being ' +
'ignored');
} else {
// Use capabilities if multiCapabilities is empty.
config.multiCapabilities = [config.capabilities];
Expand Down

0 comments on commit 8b5ae8b

Please sign in to comment.