throw real exceptions instead of die() when it makes sense
Showing
1 changed file
with
19 additions
and
19 deletions
... | @@ -1687,10 +1687,10 @@ Casper.prototype.wait = function wait(timeout, then) { | ... | @@ -1687,10 +1687,10 @@ Casper.prototype.wait = function wait(timeout, then) { |
1687 | this.checkStarted(); | 1687 | this.checkStarted(); |
1688 | timeout = ~~timeout; | 1688 | timeout = ~~timeout; |
1689 | if (timeout < 1) { | 1689 | if (timeout < 1) { |
1690 | this.die("wait() only accepts a positive integer > 0 as a timeout value"); | 1690 | throw new CasperError("wait() only accepts a positive integer > 0 as a timeout value"); |
1691 | } | 1691 | } |
1692 | if (then && !utils.isFunction(then)) { | 1692 | if (then && !utils.isFunction(then)) { |
1693 | this.die("wait() a step definition must be a function"); | 1693 | throw new CasperError("wait() a step definition must be a function"); |
1694 | } | 1694 | } |
1695 | return this.then(function _step() { | 1695 | return this.then(function _step() { |
1696 | this.waitStart(); | 1696 | this.waitStart(); |
... | @@ -1730,10 +1730,10 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { | ... | @@ -1730,10 +1730,10 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { |
1730 | this.checkStarted(); | 1730 | this.checkStarted(); |
1731 | timeout = timeout ? timeout : this.options.waitTimeout; | 1731 | timeout = timeout ? timeout : this.options.waitTimeout; |
1732 | if (!utils.isFunction(testFx)) { | 1732 | if (!utils.isFunction(testFx)) { |
1733 | this.die("waitFor() needs a test function"); | 1733 | throw new CasperError("waitFor() needs a test function"); |
1734 | } | 1734 | } |
1735 | if (then && !utils.isFunction(then)) { | 1735 | if (then && !utils.isFunction(then)) { |
1736 | this.die("waitFor() next step definition must be a function"); | 1736 | throw new CasperError("waitFor() next step definition must be a function"); |
1737 | } | 1737 | } |
1738 | return this.then(function _step() { | 1738 | return this.then(function _step() { |
1739 | this.waitStart(); | 1739 | this.waitStart(); |
... | @@ -1742,24 +1742,24 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { | ... | @@ -1742,24 +1742,24 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { |
1742 | var interval = setInterval(function _check(self, testFx, timeout, onTimeout) { | 1742 | var interval = setInterval(function _check(self, testFx, timeout, onTimeout) { |
1743 | if ((new Date().getTime() - start < timeout) && !condition) { | 1743 | if ((new Date().getTime() - start < timeout) && !condition) { |
1744 | condition = testFx.call(self, self); | 1744 | condition = testFx.call(self, self); |
1745 | return; | ||
1746 | } | ||
1747 | self.waitDone(); | ||
1748 | if (!condition) { | ||
1749 | self.log("Casper.waitFor() timeout", "warning"); | ||
1750 | self.emit('waitFor.timeout'); | ||
1751 | var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; | ||
1752 | if (!utils.isFunction(onWaitTimeout)) { | ||
1753 | throw new CasperError('Invalid timeout function, exiting.'); | ||
1754 | } | ||
1755 | onWaitTimeout.call(self, timeout); | ||
1745 | } else { | 1756 | } else { |
1746 | self.waitDone(); | 1757 | self.log(f("waitFor() finished in %dms.", new Date().getTime() - start), "info"); |
1747 | if (!condition) { | 1758 | if (then) { |
1748 | self.log("Casper.waitFor() timeout", "warning"); | 1759 | self.then(then); |
1749 | self.emit('waitFor.timeout'); | ||
1750 | var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; | ||
1751 | if (!utils.isFunction(onWaitTimeout)) { | ||
1752 | throw new CasperError('Invalid timeout function, exiting.'); | ||
1753 | } | ||
1754 | onWaitTimeout.call(self, timeout); | ||
1755 | } else { | ||
1756 | self.log(f("waitFor() finished in %dms.", new Date().getTime() - start), "info"); | ||
1757 | if (then) { | ||
1758 | self.then(then); | ||
1759 | } | ||
1760 | } | 1760 | } |
1761 | clearInterval(interval); | ||
1762 | } | 1761 | } |
1762 | clearInterval(interval); | ||
1763 | }, 100, this, testFx, timeout, onTimeout); | 1763 | }, 100, this, testFx, timeout, onTimeout); |
1764 | }); | 1764 | }); |
1765 | }; | 1765 | }; | ... | ... |
-
Please register or sign in to post a comment