Commit 3f07a5b3 3f07a5b39edc1f495c6e6376c28aa55308e1cbae by Nathan Black

Handle wait timeouts in the callback and not the event to fix selftest failures.

1 parent 49ec2987
......@@ -2009,7 +2009,8 @@ Casper.prototype.waitDone = function waitDone() {
Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, details) {
"use strict";
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
timeout = timeout || this.options.waitTimeout;
details = details || { testFx: testFx };
if (!utils.isFunction(testFx)) {
throw new CasperError("waitFor() needs a test function");
}
......@@ -2030,13 +2031,13 @@ Casper.prototype.waitFor = function waitFor(testFx, then, onTimeout, timeout, de
if (!condition) {
self.log("Casper.waitFor() timeout", "warning");
var onWaitTimeout = onTimeout ? onTimeout : self.options.onWaitTimeout;
self.emit('waitFor.timeout', timeout, details || { testFx: testFx });
self.emit('waitFor.timeout', timeout, details);
clearInterval(interval); // refs #383
if (!utils.isFunction(onWaitTimeout)) {
throw new CasperError('Invalid timeout function');
}
try {
return onWaitTimeout.call(self, timeout);
return onWaitTimeout.call(self, timeout, details);
} catch (error) {
self.emit('waitFor.timeout.error', error);
} finally {
......
......@@ -192,35 +192,6 @@ var Tester = function Tester(casper, options) {
self.processPhantomError(msg, backtrace);
});
this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout, details) {
var message = f("Wait timeout occured (%dms)", timeout);
details = details || {};
if (details.selector) {
message = f(details.waitWhile ? '"%s" never went away in %dms' : '"%s" still did not exist in %dms', details.selector, timeout);
}
else if (details.visible) {
message = f(details.waitWhile ? '"%s" never disappeared in %dms' : '"%s" never appeared in %dms', details.visible, timeout);
}
else if (details.url || details.resource) {
message = f('%s did not load in %dms', details.url || details.resource, timeout);
}
else if (details.popup) {
message = f('%s did not pop up in %dms', details.popup, timeout);
}
else if (details.text) {
message = f('"%s" did not appear in the page in %dms', details.text, timeout);
}
else if (details.selectorTextChange) {
message = f('"%s" did not have a text change in %dms', details.selectorTextChange, timeout);
}
else if (utils.isFunction(details.testFx)) {
message = f('"%s" did not evaluate to something truthy in %dms', details.testFx.toString(), timeout);
}
errorHandlerAndDone(new TimedOutError(message));
});
[
'wait.error',
'waitFor.timeout.error',
......@@ -252,7 +223,35 @@ var Tester = function Tester(casper, options) {
throw new TimedOutError(f("Timeout occured (%dms)", timeout));
};
this.casper.options.onWaitTimeout = function () {};
this.casper.options.onWaitTimeout = function test_onWaitTimeout(timeout, details) {
/*jshint maxcomplexity:10*/
var message = f("Wait timeout occured (%dms)", timeout);
details = details || {};
if (details.selector) {
message = f(details.waitWhile ? '"%s" never went away in %dms' : '"%s" still did not exist in %dms', details.selector, timeout);
}
else if (details.visible) {
message = f(details.waitWhile ? '"%s" never disappeared in %dms' : '"%s" never appeared in %dms', details.visible, timeout);
}
else if (details.url || details.resource) {
message = f('%s did not load in %dms', details.url || details.resource, timeout);
}
else if (details.popup) {
message = f('%s did not pop up in %dms', details.popup, timeout);
}
else if (details.text) {
message = f('"%s" did not appear in the page in %dms', details.text, timeout);
}
else if (details.selectorTextChange) {
message = f('"%s" did not have a text change in %dms', details.selectorTextChange, timeout);
}
else if (utils.isFunction(details.testFx)) {
message = f('"%s" did not evaluate to something truthy in %dms', details.testFx.toString(), timeout);
}
errorHandlerAndDone(new TimedOutError(message));
};
};
// Tester class is an EventEmitter
......@@ -880,7 +879,7 @@ Tester.prototype.assertInstanceOf = function assertInstanceOf(subject, construct
standard: f('Subject is instance of: "%s"', constructor.name),
values: {
subject: subject,
constructorName: constructor.name,
constructorName: constructor.name
}
});
};
......