Commit 1cd0afe2 1cd0afe201727d4412a5ce2d09941d3d1ee1ad37 by Nicolas Perriault

closes #98 - Add support for PhantomJS WebPage#onError()

1 parent f608e3cb
......@@ -1251,6 +1251,9 @@ function createPage(casper) {
casper.log(msg, level, "remote");
casper.emit('remote.message', msg);
};
page.onError = function onError(msg, trace) {
casper.emit('page.error', msg, trace);
};
page.onInitialized = function onInitialized() {
casper.emit('page.initialized', this);
if (utils.isFunction(casper.options.onPageInitialized)) {
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS error test</title>
</head>
<body>
<script>plop(); // intentional error here</script>
</body>
</html>
casper.test.comment("page.error event");
var error = {};
casper.start();
casper.on("page.error", function onError(msg, trace) {
error.msg = msg;
error.trace = trace;
});
casper.thenOpen('tests/site/error.html', function() {
this.test.assertEquals(error.msg, "ReferenceError: Can't find variable: plop", 'page.error event has been caught OK');
this.test.assertMatch(error.trace[0].file, /error.html/, 'page.error retrieves correct stack trace');
});
casper.run(function() {
this.test.done();
});