closes #98 - Add support for PhantomJS WebPage#onError()
Showing
3 changed files
with
32 additions
and
0 deletions
... | @@ -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)) { | ... | ... |
tests/site/error.html
0 → 100644
tests/suites/casper/onerror.js
0 → 100644
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 | }); |
-
Please register or sign in to post a comment