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
44767e24
...
44767e2419b539cb02effe5697e9f2fa39d2fd80
authored
2011-11-06 15:10:52 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.wait() for pausing step execution for a given amount of time
1 parent
0c56753a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
casper.js
tests/run.js
casper.js
View file @
44767e2
...
...
@@ -163,14 +163,14 @@
self
.
log
(
stepInfo
+
self
.
page
.
evaluate
(
function
()
{
return
document
.
location
.
href
;
})
+
' (HTTP '
+
self
.
currentHTTPStatus
+
')'
,
"info"
);
if
(
self
.
options
.
faultTolerant
)
{
try
{
step
(
self
);
}
catch
(
e
)
{
try
{
step
(
self
);
}
catch
(
e
)
{
if
(
self
.
options
.
faultTolerant
)
{
self
.
log
(
"Step error: "
+
e
,
"error"
);
}
else
{
throw
e
;
}
}
else
{
step
(
self
);
}
var
time
=
new
Date
().
getTime
()
-
self
.
startTime
;
self
.
log
(
stepInfo
+
"done in "
+
time
+
"ms."
,
"info"
);
...
...
@@ -634,6 +634,36 @@
},
/**
* Waits a given amount of time (expressed in milliseconds) before
* processing next step, which can passed as an optional argument.
*
* @param Number timeout The max amount of time to wait, in milliseconds
* @param Function then Next step to process (optional)
* @return Casper
*/
wait
:
function
(
timeout
,
then
)
{
if
(
typeof
(
timeout
)
!==
"number"
||
Number
(
timeout
,
10
)
<
1
)
{
this
.
die
(
"wait() only accepts a positive integer > 0 as a timeout value"
);
}
if
(
then
&&
typeof
(
then
)
!==
"function"
)
{
this
.
die
(
"wait() a step definition must be a function"
);
}
this
.
delayedExecution
=
true
;
var
start
=
new
Date
().
getTime
();
var
interval
=
setInterval
(
function
(
self
,
then
)
{
if
(
!
new
Date
().
getTime
()
-
start
<
timeout
)
{
self
.
delayedExecution
=
false
;
self
.
log
(
"wait() finished wating for "
+
timeout
+
"ms."
,
"info"
);
if
(
then
)
{
self
.
then
(
then
);
}
clearInterval
(
interval
);
}
},
100
,
this
,
then
);
return
this
;
},
/**
* Waits until a function returns true to process a next step.
*
* @param Function testFx A function to be evaluated for returning condition satisfecit
...
...
@@ -645,10 +675,10 @@
waitFor
:
function
(
testFx
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
if
(
typeof
testFx
!==
"function"
)
{
this
.
die
(
"wait
Until
() needs a test function"
);
this
.
die
(
"wait
For
() needs a test function"
);
}
if
(
then
&&
typeof
then
!==
"function"
)
{
this
.
die
(
"wait
Until
() next step definition must be a function"
);
this
.
die
(
"wait
For
() next step definition must be a function"
);
}
this
.
delayedExecution
=
true
;
var
start
=
new
Date
().
getTime
();
...
...
tests/run.js
View file @
44767e2
...
...
@@ -136,8 +136,17 @@ casper.then(function(self) {
casper
.
options
.
verbose
=
true
;
});
// Casper.wait
var
start
=
new
Date
().
getTime
();
casper
.
wait
(
1000
);
casper
.
then
(
function
(
self
)
{
casper
.
test
.
comment
(
'wait'
);
self
.
test
.
assert
(
new
Date
().
getTime
()
-
start
>
1000
,
'Casper.wait() can wait for a given amount of time'
);
});
// Casper.waitFor
casper
.
thenOpen
(
'tests/site/waitFor.html'
,
function
(
self
)
{
casper
.
test
.
comment
(
'waitFor'
);
self
.
waitFor
(
function
(
self
)
{
return
self
.
evaluate
(
function
()
{
return
document
.
querySelectorAll
(
'li'
).
length
===
4
;
...
...
Please
register
or
sign in
to post a comment