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
8cf9aaaf
...
8cf9aaaf3ffcc5271886446e83f5a751154a2e10
authored
2011-11-25 13:15:52 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #15 - added Casper.options.onResourceRequested() and Casper.options.onResou…
…rceReceived() callbacks
1 parent
09fe2ca2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletions
casper.js
tests/run.js
casper.js
View file @
8cf9aaa
...
...
@@ -49,6 +49,8 @@
onError
:
null
,
onLoadError
:
null
,
onPageInitialized
:
null
,
onResourceReceived
:
null
,
onResourceRequested
:
null
,
onStepComplete
:
null
,
onStepTimeout
:
null
,
onTimeout
:
null
,
...
...
@@ -1714,6 +1716,9 @@
casper
.
loadInProgress
=
false
;
};
page
.
onResourceReceived
=
function
(
resource
)
{
if
(
isType
(
casper
.
options
.
onResourceReceived
,
"function"
))
{
casper
.
options
.
onResourceReceived
(
casper
,
resource
);
}
if
(
resource
.
url
===
casper
.
requestUrl
&&
resource
.
stage
===
"start"
)
{
casper
.
currentHTTPStatus
=
resource
.
status
;
if
(
isType
(
casper
.
options
.
httpStatusHandlers
,
"object"
)
&&
resource
.
status
in
casper
.
options
.
httpStatusHandlers
)
{
...
...
@@ -1722,6 +1727,11 @@
casper
.
currentUrl
=
resource
.
url
;
}
};
page
.
onResourceRequested
=
function
(
request
)
{
if
(
isType
(
casper
.
options
.
onResourceRequested
,
"function"
))
{
casper
.
options
.
onResourceRequested
(
casper
,
request
);
}
};
return
page
;
}
...
...
tests/run.js
View file @
8cf9aaa
...
...
@@ -216,13 +216,32 @@ casper.thenOpen('tests/site/global.html', function(self) {
// Casper.options.onStepComplete
casper
.
then
(
function
(
self
)
{
self
.
options
.
onStepComplete
=
function
(
self
,
stepResult
)
{
self
.
test
.
comment
(
'Casper.options.onStepComplete()'
)
self
.
test
.
comment
(
'Casper.options.onStepComplete()'
)
;
self
.
test
.
assertEquals
(
stepResult
,
'ok'
,
'Casper.options.onStepComplete() is called on step complete'
);
self
.
options
.
onStepComplete
=
null
;
};
return
'ok'
;
});
// Casper.options.onResourceRequested & Casper.options.onResourceReceived
casper
.
then
(
function
(
self
)
{
self
.
options
.
onResourceReceived
=
function
(
self
,
resource
)
{
self
.
test
.
comment
(
'Casper.options.onResourceReceived()'
);
self
.
test
.
assertType
(
resource
,
'object'
,
'Casper.options.onResourceReceived() retrieve a resource object'
);
self
.
test
.
assert
(
'status'
in
resource
,
'Casper.options.onResourceReceived() retrieve a valid resource object'
)
self
.
options
.
onResourceReceived
=
null
;
};
self
.
options
.
onResourceRequested
=
function
(
self
,
request
)
{
self
.
test
.
comment
(
'Casper.options.onResourceRequested()'
);
self
.
test
.
assertType
(
request
,
'object'
,
'Casper.options.onResourceRequested() retrieve a request object'
);
self
.
test
.
assert
(
'method'
in
request
,
'Casper.options.onResourceRequested() retrieve a valid request object'
)
self
.
options
.
onResourceRequested
=
null
;
};
self
.
thenOpen
(
'tests/site/page1.html'
);
});
// History
casper
.
thenOpen
(
'tests/site/page1.html'
)
...
...
Please
register
or
sign in
to post a comment