Skip to content

Commit

Permalink
Provide real error messaging for functional test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Apr 17, 2014
1 parent fc994f7 commit 71cc889
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/wd.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,10 @@ define([
if (/* not a private interface */ key.charAt(0) !== '_') {
PromisedWebDriver.prototype[key] = function () {
var self = this,
args = Array.prototype.slice.call(arguments, 0);
args = Array.prototype.slice.call(arguments, 0),
proxyError = new Error();

Error.captureStackTrace(proxyError);

this._lastPromise = when(this._lastPromise).then(function () {
var thisArg = self,
Expand Down Expand Up @@ -784,6 +787,32 @@ define([
self._context.push(lastReturnValue);
}
return lastReturnValue;
}, function (error) {
var command = key + '(' + args.map(function (value) {
if (typeof value === 'function') {
return value.toString();
}

return JSON.stringify(value);
}).join(', ') + ')';

if (error.message.indexOf('Failed to execute') === 0) {
throw error;
}

proxyError.message = 'Failed to execute ' + command + ': ' + error.message +
(error.cause && error.cause.value && error.cause.value.message ?
' ' + error.cause.value.message : '');

for (var k in error) {
if (k === 'message' || k === 'inspect' || k === 'stack') {
continue;
}

proxyError[k] = error[k];
}

throw proxyError;
});

return this;
Expand Down

0 comments on commit 71cc889

Please sign in to comment.