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
5fcb2361
...
5fcb23612efeae87ce63ad5b87d9676f291d11e3
authored
2013-09-27 14:20:25 -0700
by
Brandon Bethke
Committed by
Nicolas Perriault
2013-11-26 23:30:34 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added hook for webpage.onResourceError
1 parent
9c546d59
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
docs/modules/casper.rst
modules/casper.js
tests/suites/casper/hooks.js
docs/modules/casper.rst
View file @
5fcb236
...
...
@@ -176,6 +176,17 @@ 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 @
5fcb236
...
...
@@ -97,6 +97,7 @@ var Casper = function Casper(options) {
onPageInitialized
:
null
,
onResourceReceived
:
null
,
onResourceRequested
:
null
,
onResourceError
:
null
,
onRunComplete
:
function
_onRunComplete
()
{
this
.
exit
();
},
...
...
@@ -2544,6 +2545,12 @@ function createPage(casper) {
casper
.
options
.
onResourceRequested
.
call
(
casper
,
casper
,
requestData
,
request
);
}
};
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"
);
casper
.
navigationRequested
=
false
;
...
...
tests/suites/casper/hooks.js
View file @
5fcb236
...
...
@@ -50,6 +50,25 @@ 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
)
{
...
...
Please
register
or
sign in
to post a comment