Commit d9ac3180 d9ac3180f5cf10600926b349e8c79ec1c9778216 by Nicolas Perriault

Merge pull request #726 from n1k0/resource-error-event

Trigger a "resource-error" event on resource loading failure
2 parents ea6b83e3 8a75d22e
......@@ -349,6 +349,16 @@ Emitted when a remote `window.callPhantom(data) <https://github.com/ariya/phanto
Emitted when any remote console logging call has been performed.
``resource.error``
~~~~~~~~~~~~~~~~~~~~~
**Arguments:** ``resourceError``
Emitted when any requested resource fails to load properly. The received ``resourceError`` object has the following properties:
- ``errorCode``: HTTP status code received
- ``url``: resource url
``resource.received``
~~~~~~~~~~~~~~~~~~~~~
......
......@@ -2558,6 +2558,9 @@ function createPage(casper) {
casper.options.onResourceRequested.call(casper, casper, requestData, request);
}
};
page.onResourceError = function onResourceError(resourceError) {
casper.emit('resource.error', resourceError);
};
page.onUrlChanged = function onUrlChanged(url) {
casper.log(f('url changed to "%s"', url), "debug");
casper.navigationRequested = false;
......
......@@ -20,3 +20,16 @@ casper.test.begin("Basic resources tests", 5, function(test) {
test.done();
});
});
casper.test.begin('"resource.error" event', 3, function(test) {
casper.on("resource.error", function(error) {
test.assertType(error, "object", '"resource.error" triggered error information');
test.assert(error.errorCode === 203, '"resource.error" error code is correct');
test.assertMatch(error.url, /non-existant\.html$/, '"resource.error" url is correct');
});
casper.start('tests/site/non-existant.html').run(function() {
casper.removeAllListeners("resource.error");
test.done();
});
});
......