closes #649 - added resource.error event
Showing
5 changed files
with
23 additions
and
34 deletions
... | @@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto | ... | @@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto |
349 | 349 | ||
350 | Emitted when any remote console logging call has been performed. | 350 | Emitted when any remote console logging call has been performed. |
351 | 351 | ||
352 | ``resource.error`` | ||
353 | ~~~~~~~~~~~~~~~~~~~~~ | ||
354 | |||
355 | **Arguments:** ``resourceError`` | ||
356 | |||
357 | Emitted when any requested resource fails to load properly. The received ``resourceError`` object has the following properties: | ||
358 | |||
359 | - ``errorCode``: HTTP status code received | ||
360 | - ``url``: resource url | ||
361 | |||
352 | ``resource.received`` | 362 | ``resource.received`` |
353 | ~~~~~~~~~~~~~~~~~~~~~ | 363 | ~~~~~~~~~~~~~~~~~~~~~ |
354 | 364 | ... | ... |
... | @@ -176,17 +176,6 @@ Proxy method for PhantomJS' WebPage#onResourceRequested() callback, but the curr | ... | @@ -176,17 +176,6 @@ Proxy method for PhantomJS' WebPage#onResourceRequested() callback, but the curr |
176 | 176 | ||
177 | .. index:: Step stack | 177 | .. index:: Step stack |
178 | 178 | ||
179 | ``onResourceError`` | ||
180 | ------------------------------------------------------------------------------- | ||
181 | |||
182 | **Type:** ``Function`` | ||
183 | |||
184 | **Default:** ``null`` | ||
185 | |||
186 | Proxy method for PhantomJS' WebPage#onResourceError() callback, but the current Casper instance is passed as first argument. | ||
187 | |||
188 | .. index:: Step stack | ||
189 | |||
190 | ``onStepComplete`` | 179 | ``onStepComplete`` |
191 | ------------------------------------------------------------------------------- | 180 | ------------------------------------------------------------------------------- |
192 | 181 | ... | ... |
... | @@ -97,7 +97,6 @@ var Casper = function Casper(options) { | ... | @@ -97,7 +97,6 @@ var Casper = function Casper(options) { |
97 | onPageInitialized: null, | 97 | onPageInitialized: null, |
98 | onResourceReceived: null, | 98 | onResourceReceived: null, |
99 | onResourceRequested: null, | 99 | onResourceRequested: null, |
100 | onResourceError: null, | ||
101 | onRunComplete: function _onRunComplete() { | 100 | onRunComplete: function _onRunComplete() { |
102 | this.exit(); | 101 | this.exit(); |
103 | }, | 102 | }, |
... | @@ -2547,9 +2546,6 @@ function createPage(casper) { | ... | @@ -2547,9 +2546,6 @@ function createPage(casper) { |
2547 | }; | 2546 | }; |
2548 | page.onResourceError = function onResourceError(resourceError) { | 2547 | page.onResourceError = function onResourceError(resourceError) { |
2549 | casper.emit('resource.error', resourceError); | 2548 | casper.emit('resource.error', resourceError); |
2550 | if (utils.isFunction(casper.options.onResourceError)) { | ||
2551 | casper.options.onResourceError.call(casper, casper, resourceError); | ||
2552 | } | ||
2553 | }; | 2549 | }; |
2554 | page.onUrlChanged = function onUrlChanged(url) { | 2550 | page.onUrlChanged = function onUrlChanged(url) { |
2555 | casper.log(f('url changed to "%s"', url), "debug"); | 2551 | casper.log(f('url changed to "%s"', url), "debug"); | ... | ... |
... | @@ -50,25 +50,6 @@ casper.test.begin('onResourceRequested() & onResourceReceived() hook tests', 6, | ... | @@ -50,25 +50,6 @@ casper.test.begin('onResourceRequested() & onResourceReceived() hook tests', 6, |
50 | }); | 50 | }); |
51 | }); | 51 | }); |
52 | 52 | ||
53 | casper.test.begin('onResourceError() hook tests', 3, function(test) { | ||
54 | var error = null; | ||
55 | casper.options.onResourceError = function(self, resourceError) { | ||
56 | error = resourceError; | ||
57 | }; | ||
58 | |||
59 | casper.start('tests/site/non-existant.html', function() { | ||
60 | var expectedPath = '/tests/site/non-existant.html'; | ||
61 | test.assert(error !== null, 'onResourceError() called with error information'); | ||
62 | test.assert(error.errorCode === 203, 'onResourceError() error code is correct'); | ||
63 | test.assert((error.url.indexOf(expectedPath, error.url.length - expectedPath.length) !== -1), 'onResourceError() url is correct'); | ||
64 | }) | ||
65 | |||
66 | casper.run(function() { | ||
67 | this.options.onResourceError = undefined; | ||
68 | test.done(); | ||
69 | }); | ||
70 | }); | ||
71 | |||
72 | casper.test.begin('onAlert() hook tests', 1, function(test) { | 53 | casper.test.begin('onAlert() hook tests', 1, function(test) { |
73 | var message; | 54 | var message; |
74 | casper.options.onAlert = function(self, msg) { | 55 | casper.options.onAlert = function(self, msg) { | ... | ... |
... | @@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) { | ... | @@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) { |
20 | test.done(); | 20 | test.done(); |
21 | }); | 21 | }); |
22 | }); | 22 | }); |
23 | |||
24 | casper.test.begin('"resource.error" event', 3, function(test) { | ||
25 | casper.on("resource.error", function(error) { | ||
26 | test.assertType(error, "object", '"resource.error" triggered error information'); | ||
27 | test.assert(error.errorCode === 203, '"resource.error" error code is correct'); | ||
28 | test.assertMatch(error.url, /non-existant\.html$/, '"resource.error" url is correct'); | ||
29 | }); | ||
30 | |||
31 | casper.start('tests/site/non-existant.html').run(function() { | ||
32 | casper.removeAllListeners("resource.error"); | ||
33 | test.done(); | ||
34 | }); | ||
35 | }); | ... | ... |
-
Please register or sign in to post a comment