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
30e703d6
...
30e703d66462d543e4438b8ab2be0cf4177c6f13
authored
2011-12-13 12:03:53 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed test for Casper.waitForResource() where a resource is not requested two times consecutively
1 parent
4dc8e4ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
21 deletions
lib/casper.js
tests/site/resources.html
tests/suites/casper/resources.coffee
lib/casper.js
View file @
30e703d
...
...
@@ -597,14 +597,14 @@
/**
* 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,
* @param Function/String test A test function or string. In case a string is passed,
url matching will be tested.
* @return Boolean
*/
resourceExists
:
function
(
test
)
{
var
testFn
;
if
(
isType
(
test
,
"string"
))
{
testFn
=
function
(
res
)
{
return
res
.
url
.
match
(
test
)
;
return
res
.
url
.
search
(
test
)
!==
-
1
;
};
}
else
{
testFn
=
test
;
...
...
@@ -670,7 +670,6 @@
if
(
!
skipLog
)
{
this
.
log
(
stepInfo
+
": done in "
+
(
new
Date
().
getTime
()
-
this
.
startTime
)
+
"ms."
,
"info"
);
}
this
.
step
++
;
},
/**
...
...
@@ -744,17 +743,21 @@
}
// check if casper is running
if
(
this
.
checker
===
null
)
{
// append step to the end of the queue
step
.
level
=
0
;
this
.
steps
.
push
(
step
);
// append step to the end of the queue
step
.
level
=
0
;
this
.
steps
.
push
(
step
);
}
else
{
// insert substep a level deeper
step
.
level
=
this
.
steps
[
this
.
step
-
1
].
level
+
1
;
var
insertIndex
=
this
.
step
;
while
(
this
.
steps
[
insertIndex
]
&&
step
.
level
===
this
.
steps
[
insertIndex
].
level
)
{
insertIndex
++
;
}
this
.
steps
.
splice
(
insertIndex
,
0
,
step
);
// insert substep a level deeper
try
{
step
.
level
=
this
.
steps
[
this
.
step
-
1
].
level
+
1
;
}
catch
(
e
)
{
step
.
level
=
0
;
}
var
insertIndex
=
this
.
step
;
while
(
this
.
steps
[
insertIndex
]
&&
step
.
level
===
this
.
steps
[
insertIndex
].
level
)
{
insertIndex
++
;
}
this
.
steps
.
splice
(
insertIndex
,
0
,
step
);
}
return
this
;
},
...
...
@@ -899,7 +902,7 @@
self
.
waitStart
();
var
start
=
new
Date
().
getTime
();
var
condition
=
false
;
var
interval
=
setInterval
(
function
(
self
,
testFx
,
onTimeout
)
{
var
interval
=
setInterval
(
function
(
self
,
testFx
,
timeout
,
onTimeout
)
{
if
((
new
Date
().
getTime
()
-
start
<
timeout
)
&&
!
condition
)
{
condition
=
testFx
(
self
);
}
else
{
...
...
@@ -909,7 +912,7 @@
if
(
isType
(
onTimeout
,
"function"
))
{
onTimeout
.
call
(
self
,
self
);
}
else
{
self
.
die
(
"
Expired timeout
, exiting."
,
"error"
);
self
.
die
(
"
Timeout of "
+
timeout
+
"ms expired
, exiting."
,
"error"
);
}
clearInterval
(
interval
);
}
else
{
...
...
@@ -920,7 +923,7 @@
clearInterval
(
interval
);
}
}
},
100
,
self
,
testFx
,
onTimeout
);
},
100
,
self
,
testFx
,
timeout
,
onTimeout
);
});
},
...
...
tests/site/resources.html
View file @
30e703d
...
...
@@ -5,7 +5,8 @@
<title>
CasperJS test resource
</title>
<script>
setTimeout
(
function
()
{
document
.
querySelector
(
"img"
).
setAttribute
(
"src"
,
"images/phantom.png"
);
var
path
=
"images/phantom.png?"
+
new
Date
();
document
.
querySelector
(
"img"
).
setAttribute
(
"src"
,
path
);
},
1000
);
</script>
</head>
...
...
tests/suites/casper/resources.coffee
View file @
30e703d
do
(
casper
)
->
casper
.
onError
=
->
console
.
log
'err'
casper
.
start
"tests/site/resources.html"
,
->
console
.
log
'loaded'
@
test
.
assertEquals
@
resources
.
length
,
1
,
"only one resource found"
@
waitForResource
"phantom.png"
,
->
onTime
=
->
@
test
.
assertEquals
(
@
resources
.
length
2
...
...
@@ -18,5 +15,7 @@ do(casper) ->
"phantom.png"
"phantom image found via test string"
)
onTimeout
=
->
@
test
.
fail
"waitForResource timeout occured"
@
waitForResource
"phantom.png"
,
onTime
,
onTimeout
casper
.
run
(
->
@
test
.
done
())
...
...
Please
register
or
sign in
to post a comment