fixes #249 - default timeout functions don't die() anymore in tests
Also, a new `onWaitTimeout` option has been added in order to set a desired behavior when a `wait*` function times out.
Showing
3 changed files
with
35 additions
and
15 deletions
... | @@ -8,7 +8,8 @@ This version is yet to be released. | ... | @@ -8,7 +8,8 @@ This version is yet to be released. |
8 | 8 | ||
9 | ### Important Changes & Caveats | 9 | ### Important Changes & Caveats |
10 | 10 | ||
11 | **BC BREAK**: - fixes [#220](https://github.com/n1k0/casperjs/issues/220), [#237](https://github.com/n1k0/casperjs/issues/237) - added a `waitTimeout` options, removed `defaultWaitTimeout` option. | 11 | **BC BREAK**: fixes [#220](https://github.com/n1k0/casperjs/issues/220), [#237](https://github.com/n1k0/casperjs/issues/237) - added a `waitTimeout` options, removed `defaultWaitTimeout` option. |
12 | **BC BREAK** (for the better): fixes [#249](https://github.com/n1k0/casperjs/issues/249) - default timeout functions don't `die()` anymore in tests | ||
12 | **BC BREAK** (for the better): merged [#188](https://github.com/n1k0/casperjs/issues/188) - Easy access to current response object; | 13 | **BC BREAK** (for the better): merged [#188](https://github.com/n1k0/casperjs/issues/188) - Easy access to current response object; |
13 | You can now access the current response object as the first parameter of step callbacks: | 14 | You can now access the current response object as the first parameter of step callbacks: |
14 | 15 | ||
... | @@ -64,6 +65,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca | ... | @@ -64,6 +65,7 @@ The documentation has been [updated accordingly](http://casperjs.org/api.html#ca |
64 | 65 | ||
65 | ### Bugfixes & enhancements | 66 | ### Bugfixes & enhancements |
66 | 67 | ||
68 | - a new `onWaitTimeout` option has been added, to allow defining a default behavior when a `waitFor*` function times out. | ||
67 | - [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses. | 69 | - [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses. |
68 | - closes [#205](https://github.com/n1k0/casperjs/issues/205) - [`debugHTML()`](http://casperjs.org/api.html#casper.debugHTML) can have a selector passed; added [`getHTML()`](http://casperjs.org/api.html#casper.getHTML) | 70 | - closes [#205](https://github.com/n1k0/casperjs/issues/205) - [`debugHTML()`](http://casperjs.org/api.html#casper.debugHTML) can have a selector passed; added [`getHTML()`](http://casperjs.org/api.html#casper.getHTML) |
69 | - closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds) | 71 | - closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds) | ... | ... |
... | @@ -94,8 +94,15 @@ var Casper = function Casper(options) { | ... | @@ -94,8 +94,15 @@ var Casper = function Casper(options) { |
94 | onResourceReceived: null, | 94 | onResourceReceived: null, |
95 | onResourceRequested: null, | 95 | onResourceRequested: null, |
96 | onStepComplete: null, | 96 | onStepComplete: null, |
97 | onStepTimeout: null, | 97 | onStepTimeout: function _onStepTimeout(timeout, stepNum) { |
98 | onTimeout: null, | 98 | this.die("Maximum step execution timeout exceeded for step " + stepNum); |
99 | }, | ||
100 | onTimeout: function _onTimeout(timeout) { | ||
101 | this.die(f("Script timeout of %dms reached, exiting.", timeout)); | ||
102 | }, | ||
103 | onWaitTimeout: function _onWaitTimeout(timeout) { | ||
104 | this.die(f("Wait timeout of %dms expired, exiting.", timeout)); | ||
105 | }, | ||
99 | page: null, | 106 | page: null, |
100 | pageSettings: { | 107 | pageSettings: { |
101 | localToRemoteUrlAccessEnabled: true, | 108 | localToRemoteUrlAccessEnabled: true, |
... | @@ -556,12 +563,14 @@ Casper.prototype.evaluate = function evaluate(fn, context) { | ... | @@ -556,12 +563,14 @@ Casper.prototype.evaluate = function evaluate(fn, context) { |
556 | * | 563 | * |
557 | * @param function fn The expression to evaluate | 564 | * @param function fn The expression to evaluate |
558 | * @param String message The error message to log | 565 | * @param String message The error message to log |
566 | * @param Number status An optional exit status code (must be > 0) | ||
567 | * | ||
559 | * @return Casper | 568 | * @return Casper |
560 | */ | 569 | */ |
561 | Casper.prototype.evaluateOrDie = function evaluateOrDie(fn, message) { | 570 | Casper.prototype.evaluateOrDie = function evaluateOrDie(fn, message, status) { |
562 | "use strict"; | 571 | "use strict"; |
563 | if (!this.evaluate(fn)) { | 572 | if (!this.evaluate(fn)) { |
564 | return this.die(message); | 573 | return this.die(message, status); |
565 | } | 574 | } |
566 | return this; | 575 | return this; |
567 | }; | 576 | }; |
... | @@ -1139,9 +1148,7 @@ Casper.prototype.runStep = function runStep(step) { | ... | @@ -1139,9 +1148,7 @@ Casper.prototype.runStep = function runStep(step) { |
1139 | if ((self.test.currentSuiteNum + "-" + self.step) === stepNum) { | 1148 | if ((self.test.currentSuiteNum + "-" + self.step) === stepNum) { |
1140 | self.emit('step.timeout'); | 1149 | self.emit('step.timeout'); |
1141 | if (utils.isFunction(self.options.onStepTimeout)) { | 1150 | if (utils.isFunction(self.options.onStepTimeout)) { |
1142 | self.options.onStepTimeout.call(self, self); | 1151 | self.options.onStepTimeout.call(self, self.options.onStepTimeout, stepNum); |
1143 | } else { | ||
1144 | self.die("Maximum step execution timeout exceeded for step " + stepNum, "error"); | ||
1145 | } | 1152 | } |
1146 | } | 1153 | } |
1147 | clearInterval(stepTimeoutCheckInterval); | 1154 | clearInterval(stepTimeoutCheckInterval); |
... | @@ -1223,9 +1230,7 @@ Casper.prototype.start = function start(location, then) { | ... | @@ -1223,9 +1230,7 @@ Casper.prototype.start = function start(location, then) { |
1223 | setTimeout(function _check(self) { | 1230 | setTimeout(function _check(self) { |
1224 | self.emit('timeout'); | 1231 | self.emit('timeout'); |
1225 | if (utils.isFunction(self.options.onTimeout)) { | 1232 | if (utils.isFunction(self.options.onTimeout)) { |
1226 | self.options.onTimeout.call(self, self); | 1233 | self.options.onTimeout.call(self, self.options.timeout); |
1227 | } else { | ||
1228 | self.die(f("Timeout of %dms exceeded, exiting.", self.options.timeout)); | ||
1229 | } | 1234 | } |
1230 | }, this.options.timeout, this); | 1235 | }, this.options.timeout, this); |
1231 | } | 1236 | } |
... | @@ -1510,11 +1515,11 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { | ... | @@ -1510,11 +1515,11 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout) { |
1510 | if (!condition) { | 1515 | if (!condition) { |
1511 | self.log("Casper.waitFor() timeout", "warning"); | 1516 | self.log("Casper.waitFor() timeout", "warning"); |
1512 | self.emit('waitFor.timeout'); | 1517 | self.emit('waitFor.timeout'); |
1513 | if (utils.isFunction(onTimeout)) { | 1518 | var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; |
1514 | onTimeout.call(self, self); | 1519 | if (!utils.isFunction(onWaitTimeout)) { |
1515 | } else { | 1520 | throw new CasperError('Invalid timeout function, exiting.'); |
1516 | self.die(f("Timeout of %dms expired, exiting.", timeout), "error"); | ||
1517 | } | 1521 | } |
1522 | onWaitTimeout.call(self, timeout); | ||
1518 | } else { | 1523 | } else { |
1519 | self.log(f("waitFor() finished in %dms.", new Date().getTime() - start), "info"); | 1524 | self.log(f("waitFor() finished in %dms.", new Date().getTime() - start), "info"); |
1520 | if (then) { | 1525 | if (then) { | ... | ... |
... | @@ -77,6 +77,19 @@ var Tester = function Tester(casper, options) { | ... | @@ -77,6 +77,19 @@ var Tester = function Tester(casper, options) { |
77 | failures: [] | 77 | failures: [] |
78 | }; | 78 | }; |
79 | 79 | ||
80 | // specific timeout callbacks | ||
81 | casper.options.onStepTimeout = function test_onStepTimeout(timeout) { | ||
82 | this.test.fail(f("Step timeout occured (%dms)", timeout)); | ||
83 | }; | ||
84 | |||
85 | casper.options.onTimeout = function test_onTimeout(timeout) { | ||
86 | this.test.fail(f("Timeout occured (%dms)", timeout)); | ||
87 | }; | ||
88 | |||
89 | casper.options.onWaitTimeout = function test_onWaitTimeout(timeout) { | ||
90 | this.test.fail(f("Wait timeout occured (%dms)", timeout)); | ||
91 | }; | ||
92 | |||
80 | // events | 93 | // events |
81 | casper.on('error', function(msg, backtrace) { | 94 | casper.on('error', function(msg, backtrace) { |
82 | var line = 0; | 95 | var line = 0; | ... | ... |
-
Please register or sign in to post a comment