Commit 9e3916fc 9e3916fc4562b22495ce02394cf6b372346c58d7 by Nicolas Perriault

added new 'onTimeout' option to Casper for setting a callback when script execut…

…ion timeout is reached; also, a script will now die() on timeout by default
1 parent 885122db
......@@ -48,6 +48,7 @@
onError: null,
onLoadError: null,
onPageInitialized: null,
onTimeout: null,
page: null,
pageSettings: { userAgent: DEFAULT_USER_AGENT },
timeout: null,
......@@ -637,9 +638,13 @@
}
this.started = true;
if (isType(this.options.timeout, "number") && this.options.timeout > 0) {
this.log("execution timeout set to " + this.options.timeout + 'ms', "info");
this.log("Execution timeout set to " + this.options.timeout + 'ms', "info");
setTimeout(function(self) {
self.log("timeout of " + self.options.timeout + "ms exceeded", "info").exit();
if (isType(self.options.onTimeout, "function")) {
self.options.onTimeout(self);
} else {
self.die("Timeout of " + self.options.timeout + "ms exceeded, exiting.");
}
}, this.options.timeout, this);
}
if (isType(this.options.onPageInitialized, "function")) {
......
phantom.injectJs('casper.js');
var casper = new phantom.Casper({
logLevel: "debug",
verbose: true,
timeout: 2000,
onTimeout: function(self) {
self.die('script execution timeout exceeded');
}
});
casper.start('http://google.com/', function(self) {
self.log('google is loaded');
});
casper.run(function(self) {
self.log('oops, forgot to call Casper.exit()');
});
\ No newline at end of file