Commit 0cd63645 0cd6364511e7d1682ae46b609da0e9848a5207c4 by Nicolas Perriault

throw real exceptions instead of die() when it makes sense

1 parent 8b140127
......@@ -1687,10 +1687,10 @@ Casper.prototype.wait = function wait(timeout, then) {
this.checkStarted();
timeout = ~~timeout;
if (timeout < 1) {
this.die("wait() only accepts a positive integer > 0 as a timeout value");
throw new CasperError("wait() only accepts a positive integer > 0 as a timeout value");
}
if (then && !utils.isFunction(then)) {
this.die("wait() a step definition must be a function");
throw new CasperError("wait() a step definition must be a function");
}
return this.then(function _step() {
this.waitStart();
......@@ -1730,10 +1730,10 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
if (!utils.isFunction(testFx)) {
this.die("waitFor() needs a test function");
throw new CasperError("waitFor() needs a test function");
}
if (then && !utils.isFunction(then)) {
this.die("waitFor() next step definition must be a function");
throw new CasperError("waitFor() next step definition must be a function");
}
return this.then(function _step() {
this.waitStart();
......@@ -1742,7 +1742,8 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
var interval = setInterval(function _check(self, testFx, timeout, onTimeout) {
if ((new Date().getTime() - start < timeout) && !condition) {
condition = testFx.call(self, self);
} else {
return;
}
self.waitDone();
if (!condition) {
self.log("Casper.waitFor() timeout", "warning");
......@@ -1759,7 +1760,6 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) {
}
}
clearInterval(interval);
}
}, 100, this, testFx, timeout, onTimeout);
});
};
......