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
6d4f7d54
...
6d4f7d54aeb997c17592339896142bff95b68557
authored
2011-09-07 12:13:59 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.repeat() method for easy definition of repeated steps
1 parent
53af6efc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
casper.js
casper.js
View file @
6d4f7d5
...
...
@@ -104,14 +104,15 @@
* @param function onComplete An options callback to apply on completion
*/
checkStep
:
function
(
self
,
onComplete
)
{
if
(
!
self
.
loadInProgress
&&
typeof
(
self
.
steps
[
self
.
step
])
===
"function"
)
{
var
step
=
self
.
steps
[
self
.
step
];
if
(
!
self
.
loadInProgress
&&
typeof
(
step
)
===
"function"
)
{
var
curStepNum
=
self
.
step
+
1
,
stepInfo
=
"Step "
+
curStepNum
+
"/"
+
self
.
steps
.
length
+
": "
;
self
.
log
(
stepInfo
+
self
.
page
.
evaluate
(
function
()
{
return
document
.
location
.
href
;
})
+
' (HTTP '
+
self
.
currentHTTPStatus
+
')'
,
"info"
);
try
{
s
elf
.
steps
[
self
.
step
]
(
self
);
s
tep
(
self
);
}
catch
(
e
)
{
self
.
log
(
"Fatal: "
+
e
,
"error"
);
}
...
...
@@ -119,7 +120,7 @@
self
.
log
(
stepInfo
+
"done in "
+
time
+
"ms."
,
"info"
);
self
.
step
++
;
}
if
(
typeof
(
s
elf
.
steps
[
self
.
step
]
)
!==
"function"
)
{
if
(
typeof
(
s
tep
)
!==
"function"
)
{
self
.
result
.
time
=
new
Date
().
getTime
()
-
self
.
startTime
;
self
.
log
(
"Done "
+
self
.
steps
.
length
+
" steps in "
+
self
.
result
.
time
+
'ms.'
,
"info"
);
clearInterval
(
self
.
checker
);
...
...
@@ -189,7 +190,7 @@
* WebPage#evaluate does, but can also replace values by their
* placeholer names:
*
*
navigato
r.evaluate(function() {
*
caspe
r.evaluate(function() {
* document.querySelector('#username').setAttribute('value', '%username%');
* document.querySelector('#password').setAttribute('value', '%password%');
* document.querySelector('#submit').click();
...
...
@@ -287,6 +288,21 @@
},
/**
* Repeats a step a given number of times.
*
* @param Number times Number of times to repeat step
* @aram function step The step closure
* @return Casper
* @see Casper#then
*/
repeat
:
function
(
times
,
step
)
{
for
(
var
i
=
0
;
i
<
times
;
i
++
)
{
this
.
then
(
step
);
}
return
this
;
},
/**
* Runs the whole suite of steps.
*
* @param function onComplete an optional callback
...
...
Please
register
or
sign in
to post a comment