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
df51de7d
...
df51de7d3143965eff60a73ad72e6a6b925d28f3
authored
2012-01-05 10:48:41 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added regexp support to Casper.resourceExists()
1 parent
87c0a322
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
modules/casper.js
tests/suites/casper/resources.coffee
modules/casper.js
View file @
df51de7
...
...
@@ -612,7 +612,7 @@ Casper.prototype.log = function(message, level, space) {
message
=
f
(
'%s [%s] %s'
,
levelStr
,
space
,
message
);
}
if
(
this
.
options
.
verbose
)
{
this
.
echo
(
message
);
// direct output
this
.
echo
(
this
.
filter
(
'log.message'
,
message
)
||
message
);
// direct output
}
this
.
result
.
log
.
push
(
entry
);
this
.
emit
(
'log'
,
entry
);
...
...
@@ -675,17 +675,28 @@ Casper.prototype.repeat = function(times, then) {
/**
* Checks if a given resource was loaded by the remote page.
*
* @param Function/String test A test function or string. In case a string is passed, url matching will be tested.
* @param Function/String/RegExp test A test function, string or regular expression.
* In case a string is passed, url matching will be tested.
* @return Boolean
*/
Casper
.
prototype
.
resourceExists
=
function
(
test
)
{
var
testFn
;
if
(
utils
.
isString
(
test
))
{
testFn
=
function
(
res
)
{
switch
(
utils
.
betterTypeOf
(
test
))
{
case
"string"
:
testFn
=
function
(
res
)
{
return
res
.
url
.
search
(
test
)
!==
-
1
;
};
}
else
{
break
;
case
"regexp"
:
testFn
=
function
(
res
)
{
return
test
.
test
(
res
.
url
);
};
break
;
case
"function"
:
testFn
=
test
;
break
;
default
:
throw
new
Error
(
"Invalid type"
);
}
return
this
.
resources
.
some
(
testFn
);
};
...
...
tests/suites/casper/resources.coffee
View file @
df51de7
...
...
@@ -8,12 +8,16 @@ do(casper) ->
"two resources found"
)
@
test
.
assertResourceExists
(
/phantom\.png/i
"phantom image found via test RegExp"
)
@
test
.
assertResourceExists
(
(
res
)
->
res
.
url
.
match
"phantom.png"
"phantom image found via test
f
unction"
"phantom image found via test
F
unction"
)
@
test
.
assertResourceExists
(
"phantom.png"
"phantom image found via test
s
tring"
"phantom image found via test
S
tring"
)
onTimeout
=
->
@
test
.
fail
"waitForResource timeout occured"
@
waitForResource
"phantom.png"
,
onTime
,
onTimeout
...
...
Please
register
or
sign in
to post a comment