Handle wait timeouts in the callback and not the event to fix selftest failures.
Showing
2 changed files
with
34 additions
and
34 deletions
... | @@ -2009,7 +2009,8 @@ Casper.prototype.waitDone = function waitDone() { | ... | @@ -2009,7 +2009,8 @@ Casper.prototype.waitDone = function waitDone() { |
2009 | Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, details) { | 2009 | Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, details) { |
2010 | "use strict"; | 2010 | "use strict"; |
2011 | this.checkStarted(); | 2011 | this.checkStarted(); |
2012 | timeout = timeout ? timeout : this.options.waitTimeout; | 2012 | timeout = timeout || this.options.waitTimeout; |
2013 | details = details || { testFx: testFx }; | ||
2013 | if (!utils.isFunction(testFx)) { | 2014 | if (!utils.isFunction(testFx)) { |
2014 | throw new CasperError("waitFor() needs a test function"); | 2015 | throw new CasperError("waitFor() needs a test function"); |
2015 | } | 2016 | } |
... | @@ -2030,13 +2031,13 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de | ... | @@ -2030,13 +2031,13 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de |
2030 | if (!condition) { | 2031 | if (!condition) { |
2031 | self.log("Casper.waitFor() timeout", "warning"); | 2032 | self.log("Casper.waitFor() timeout", "warning"); |
2032 | var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; | 2033 | var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout; |
2033 | self.emit('waitFor.timeout', timeout, details || { testFx: testFx }); | 2034 | self.emit('waitFor.timeout', timeout, details); |
2034 | clearInterval(interval); // refs #383 | 2035 | clearInterval(interval); // refs #383 |
2035 | if (!utils.isFunction(onWaitTimeout)) { | 2036 | if (!utils.isFunction(onWaitTimeout)) { |
2036 | throw new CasperError('Invalid timeout function'); | 2037 | throw new CasperError('Invalid timeout function'); |
2037 | } | 2038 | } |
2038 | try { | 2039 | try { |
2039 | return onWaitTimeout.call(self, timeout); | 2040 | return onWaitTimeout.call(self, timeout, details); |
2040 | } catch (error) { | 2041 | } catch (error) { |
2041 | self.emit('waitFor.timeout.error', error); | 2042 | self.emit('waitFor.timeout.error', error); |
2042 | } finally { | 2043 | } finally { | ... | ... |
... | @@ -192,35 +192,6 @@ var Tester = function Tester(casper, options) { | ... | @@ -192,35 +192,6 @@ var Tester = function Tester(casper, options) { |
192 | self.processPhantomError(msg, backtrace); | 192 | self.processPhantomError(msg, backtrace); |
193 | }); | 193 | }); |
194 | 194 | ||
195 | this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout, details) { | ||
196 | var message = f("Wait timeout occured (%dms)", timeout); | ||
197 | details = details || {}; | ||
198 | |||
199 | if (details.selector) { | ||
200 | message = f(details.waitWhile ? '"%s" never went away in %dms' : '"%s" still did not exist in %dms', details.selector, timeout); | ||
201 | } | ||
202 | else if (details.visible) { | ||
203 | message = f(details.waitWhile ? '"%s" never disappeared in %dms' : '"%s" never appeared in %dms', details.visible, timeout); | ||
204 | } | ||
205 | else if (details.url || details.resource) { | ||
206 | message = f('%s did not load in %dms', details.url || details.resource, timeout); | ||
207 | } | ||
208 | else if (details.popup) { | ||
209 | message = f('%s did not pop up in %dms', details.popup, timeout); | ||
210 | } | ||
211 | else if (details.text) { | ||
212 | message = f('"%s" did not appear in the page in %dms', details.text, timeout); | ||
213 | } | ||
214 | else if (details.selectorTextChange) { | ||
215 | message = f('"%s" did not have a text change in %dms', details.selectorTextChange, timeout); | ||
216 | } | ||
217 | else if (utils.isFunction(details.testFx)) { | ||
218 | message = f('"%s" did not evaluate to something truthy in %dms', details.testFx.toString(), timeout); | ||
219 | } | ||
220 | |||
221 | errorHandlerAndDone(new TimedOutError(message)); | ||
222 | }); | ||
223 | |||
224 | [ | 195 | [ |
225 | 'wait.error', | 196 | 'wait.error', |
226 | 'waitFor.timeout.error', | 197 | 'waitFor.timeout.error', |
... | @@ -252,7 +223,35 @@ var Tester = function Tester(casper, options) { | ... | @@ -252,7 +223,35 @@ var Tester = function Tester(casper, options) { |
252 | throw new TimedOutError(f("Timeout occured (%dms)", timeout)); | 223 | throw new TimedOutError(f("Timeout occured (%dms)", timeout)); |
253 | }; | 224 | }; |
254 | 225 | ||
255 | this.casper.options.onWaitTimeout = function () {}; | 226 | this.casper.options.onWaitTimeout = function test_onWaitTimeout(timeout, details) { |
227 | /*jshint maxcomplexity:10*/ | ||
228 | var message = f("Wait timeout occured (%dms)", timeout); | ||
229 | details = details || {}; | ||
230 | |||
231 | if (details.selector) { | ||
232 | message = f(details.waitWhile ? '"%s" never went away in %dms' : '"%s" still did not exist in %dms', details.selector, timeout); | ||
233 | } | ||
234 | else if (details.visible) { | ||
235 | message = f(details.waitWhile ? '"%s" never disappeared in %dms' : '"%s" never appeared in %dms', details.visible, timeout); | ||
236 | } | ||
237 | else if (details.url || details.resource) { | ||
238 | message = f('%s did not load in %dms', details.url || details.resource, timeout); | ||
239 | } | ||
240 | else if (details.popup) { | ||
241 | message = f('%s did not pop up in %dms', details.popup, timeout); | ||
242 | } | ||
243 | else if (details.text) { | ||
244 | message = f('"%s" did not appear in the page in %dms', details.text, timeout); | ||
245 | } | ||
246 | else if (details.selectorTextChange) { | ||
247 | message = f('"%s" did not have a text change in %dms', details.selectorTextChange, timeout); | ||
248 | } | ||
249 | else if (utils.isFunction(details.testFx)) { | ||
250 | message = f('"%s" did not evaluate to something truthy in %dms', details.testFx.toString(), timeout); | ||
251 | } | ||
252 | |||
253 | errorHandlerAndDone(new TimedOutError(message)); | ||
254 | }; | ||
256 | }; | 255 | }; |
257 | 256 | ||
258 | // Tester class is an EventEmitter | 257 | // Tester class is an EventEmitter |
... | @@ -880,7 +879,7 @@ Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, construct | ... | @@ -880,7 +879,7 @@ Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, construct |
880 | standard: f('Subject is instance of: "%s"', constructor.name), | 879 | standard: f('Subject is instance of: "%s"', constructor.name), |
881 | values: { | 880 | values: { |
882 | subject: subject, | 881 | subject: subject, |
883 | constructorName: constructor.name, | 882 | constructorName: constructor.name |
884 | } | 883 | } |
885 | }); | 884 | }); |
886 | }; | 885 | }; | ... | ... |
-
Please register or sign in to post a comment