Commit 5ba5ae30 5ba5ae30b240772bbef425df3302c8990606f5d5 by Nicolas Perriault

fixes #722 - throw step errors are no more silenced

Introduced a new Casper `silentErrors` option which is set to `false`
by default.
1 parent 077bc3e9
......@@ -281,6 +281,17 @@ When this option is set to true — which is the default, any password informat
.. index:: Step stack, timeout
``silentErrors``
-------------------------------------------------------------------------------
**Type:** ``Boolean``
**Default:** ``false``
When this option is enabled, caught step errors are not thrown (though related events are still emitted). Mostly used internally in a testing context.
.. index:: timeout
``stepTimeout``
-------------------------------------------------------------------------------
......
......@@ -116,6 +116,7 @@ var Casper = function Casper(options) {
userAgent: defaultUserAgent
},
remoteScripts: [],
silentErrors: false,
stepTimeout: null,
timeout: null,
verbose: false,
......@@ -384,6 +385,9 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
}
} catch (error) {
self.emit('complete.error', error);
if (!self.options.silentErrors) {
throw error;
}
}
};
......@@ -1528,6 +1532,9 @@ Casper.prototype.runStep = function runStep(step) {
}
} catch (err) {
this.emit('step.error', err);
if (!this.options.silentErrors) {
throw err;
}
}
if (!skipLog) {
this.emit('step.complete', stepResult);
......@@ -1981,6 +1988,9 @@ Casper.prototype.wait = function wait(timeout, then) {
then.call(self, self);
} catch (error) {
self.emit('wait.error', error);
if (!self.options.silentErrors) {
throw error;
}
}
}
self.waitDone();
......@@ -2044,6 +2054,9 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de
return onWaitTimeout.call(self, timeout, details);
} catch (error) {
self.emit('waitFor.timeout.error', error);
if (!self.options.silentErrors) {
throw error;
}
} finally {
return;
}
......
......@@ -13,7 +13,8 @@ var f = utils.format;
var loadIncludes = ['includes', 'pre', 'post'];
var tests = [];
var casper = require('casper').create({
exitOnError: false
exitOnError: false,
silentErrors: true // we subscribe to error events for catching them
});
// local utils
......