Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
8a75d22e
...
8a75d22ea99dfbe63d523db0cae0232078044b55
authored
2013-11-26 23:45:57 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
closes #649 - added resource.error event
1 parent
5fcb2361
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
34 deletions
docs/events-filters.rst
docs/modules/casper.rst
modules/casper.js
tests/suites/casper/hooks.js
tests/suites/casper/resources.js
docs/events-filters.rst
View file @
8a75d22
...
...
@@ -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``
~~~~~~~~~~~~~~~~~~~~~
...
...
docs/modules/casper.rst
View file @
8a75d22
...
...
@@ -176,17 +176,6 @@ Proxy method for PhantomJS' WebPage#onResourceRequested() callback, but the curr
.. index:: Step stack
``onResourceError``
-------------------------------------------------------------------------------
**Type:** ``Function``
**Default:** ``null``
Proxy method for PhantomJS' WebPage#onResourceError() callback, but the current Casper instance is passed as first argument.
.. index:: Step stack
``onStepComplete``
-------------------------------------------------------------------------------
...
...
modules/casper.js
View file @
8a75d22
...
...
@@ -97,7 +97,6 @@ var Casper = function Casper(options) {
onPageInitialized
:
null
,
onResourceReceived
:
null
,
onResourceRequested
:
null
,
onResourceError
:
null
,
onRunComplete
:
function
_onRunComplete
()
{
this
.
exit
();
},
...
...
@@ -2547,9 +2546,6 @@ function createPage(casper) {
};
page
.
onResourceError
=
function
onResourceError
(
resourceError
)
{
casper
.
emit
(
'resource.error'
,
resourceError
);
if
(
utils
.
isFunction
(
casper
.
options
.
onResourceError
))
{
casper
.
options
.
onResourceError
.
call
(
casper
,
casper
,
resourceError
);
}
};
page
.
onUrlChanged
=
function
onUrlChanged
(
url
)
{
casper
.
log
(
f
(
'url changed to "%s"'
,
url
),
"debug"
);
...
...
tests/suites/casper/hooks.js
View file @
8a75d22
...
...
@@ -50,25 +50,6 @@ casper.test.begin('onResourceRequested() & onResourceReceived() hook tests', 6,
});
});
casper
.
test
.
begin
(
'onResourceError() hook tests'
,
3
,
function
(
test
)
{
var
error
=
null
;
casper
.
options
.
onResourceError
=
function
(
self
,
resourceError
)
{
error
=
resourceError
;
};
casper
.
start
(
'tests/site/non-existant.html'
,
function
()
{
var
expectedPath
=
'/tests/site/non-existant.html'
;
test
.
assert
(
error
!==
null
,
'onResourceError() called with error information'
);
test
.
assert
(
error
.
errorCode
===
203
,
'onResourceError() error code is correct'
);
test
.
assert
((
error
.
url
.
indexOf
(
expectedPath
,
error
.
url
.
length
-
expectedPath
.
length
)
!==
-
1
),
'onResourceError() url is correct'
);
})
casper
.
run
(
function
()
{
this
.
options
.
onResourceError
=
undefined
;
test
.
done
();
});
});
casper
.
test
.
begin
(
'onAlert() hook tests'
,
1
,
function
(
test
)
{
var
message
;
casper
.
options
.
onAlert
=
function
(
self
,
msg
)
{
...
...
tests/suites/casper/resources.js
View file @
8a75d22
...
...
@@ -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
();
});
});
...
...
Please
register
or
sign in
to post a comment