Commit 1cd0afe2 1cd0afe201727d4412a5ce2d09941d3d1ee1ad37 by Nicolas Perriault

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

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