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

Commit 8b5ae8b

Browse files
committed
feat(troubleshoot): Add more information when the --troubleshoot flag 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.
1 parent 7f15570 commit 8b5ae8b

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

lib/configParser.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ConfigParser.resolveFilePatterns =
9898
for (var i = 0; i < patterns.length; ++i) {
9999
var matches = glob.sync(patterns[i], {cwd: cwd});
100100
if (!matches.length && !opt_omitWarnings) {
101-
log.puts('Warning: pattern ' + patterns[i] + ' did not match any files.');
101+
log.warn('pattern ' + patterns[i] + ' did not match any files.');
102102
}
103103
for (var j = 0; j < matches.length; ++j) {
104104
resolvedFiles.push(path.resolve(cwd, matches[j]));
@@ -164,7 +164,7 @@ ConfigParser.prototype.addConfig_ = function(additionalConfig, relativeTo) {
164164

165165
// chromeOnly is deprecated, use directConnect instead.
166166
if (additionalConfig.chromeOnly) {
167-
log.puts('Warning: chromeOnly is deprecated. Use directConnect');
167+
log.warn('chromeOnly is deprecated. Use directConnect');
168168
additionalConfig.directConnect = true;
169169
}
170170
merge_(this.config_, additionalConfig);
@@ -177,13 +177,22 @@ ConfigParser.prototype.addConfig_ = function(additionalConfig, relativeTo) {
177177
* @param {String} filename
178178
*/
179179
ConfigParser.prototype.addFileConfig = function(filename) {
180-
if (!filename) {
181-
return this;
180+
try {
181+
if (!filename) {
182+
return this;
183+
}
184+
var filePath = path.resolve(process.cwd(), filename);
185+
var fileConfig = require(filePath).config;
186+
if (!fileConfig) {
187+
log.error('configuration file ' + filename + ' did not export a config ' +
188+
'object');
189+
}
190+
fileConfig.configDir = path.dirname(filePath);
191+
this.addConfig_(fileConfig, fileConfig.configDir);
192+
} catch (e) {
193+
log.error('failed loading configuration file ' + filename);
194+
throw e;
182195
}
183-
var filePath = path.resolve(process.cwd(), filename);
184-
var fileConfig = require(filePath).config;
185-
fileConfig.configDir = path.dirname(filePath);
186-
this.addConfig_(fileConfig, fileConfig.configDir);
187196
return this;
188197
};
189198

lib/launcher.js

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ var init = function(configFile, additionalConfig) {
111111
}
112112
var config = configParser.getConfig();
113113
log.set(config);
114+
log.debug('Running with --troubleshoot');
115+
log.debug('Protractor version: ' + require('../package.json').version);
116+
log.debug('Your base url for tests is ' + config.baseUrl);
114117
var scheduler = new TaskScheduler(config);
115118

116119
process.on('exit', function(code) {

lib/logger.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ var puts = function() {
2323

2424
var debug = function(msg) {
2525
if (troubleshoot) {
26-
puts(msg);
26+
puts('DEBUG - ' + msg);
2727
}
2828
};
2929

30+
var warn = function(msg) {
31+
puts('WARNING - ' + msg);
32+
}
33+
34+
var error = function(msg) {
35+
puts('ERROR - ' + msg);
36+
}
37+
3038
exports.set = set;
3139
exports.print = print;
3240
exports.puts = puts;
3341
exports.debug = debug;
42+
exports.warn = warn;
43+
exports.error = error;

lib/protractor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,9 @@ var buildElementHelper = function(ptor) {
703703
elementArrayFinder.locator_.toString());
704704
} else {
705705
if (webElements.length > 1) {
706-
log.puts('warning: more than one element found for locator ' +
706+
log.warn('more than one element found for locator ' +
707707
elementArrayFinder.locator_.toString() +
708-
' - you may need to be more specific');
708+
' - the first result will be used');
709709
}
710710
return [webElements[0]];
711711
}

lib/runner.js

+7
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ Runner.prototype.run = function() {
258258
}).then(function() {
259259
var browser = self.createBrowser();
260260
self.setupGlobals_(browser);
261+
return browser.getSession().then(function(session) {
262+
log.debug('WebDriver session successfully started with capabilities ' +
263+
util.inspect(session.getCapabilities()));
264+
}, function(err) {
265+
log.error('Unable to start a WebDriver session.');
266+
throw err;
267+
});
261268
// 3) Setup plugins
262269
}).then(function() {
263270
plugins = new Plugins(self.config_);

lib/taskScheduler.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* The taskScheduler keeps track of the specs that needs to run next
2+
* The taskScheduler keeps track of the spec files that needs to run next
33
* and which task is running what.
44
*/
55
'use strict';
@@ -34,8 +34,9 @@ var TaskScheduler = function(config) {
3434

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

0 commit comments

Comments
 (0)