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
842e9089
...
842e9089be47aec266d736e71eacc4e765e7178c
authored
2013-03-16 15:04:13 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper#eachThen()
1 parent
be5c0460
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
1 deletions
CHANGELOG.md
docs/modules/casper.rst
modules/casper.js
tests/suites/casper/steps.js
CHANGELOG.md
View file @
842e908
...
...
@@ -110,6 +110,7 @@ Last, all the casper test suites have been upgraded to use the new testing featu
-
Added
[
`Casper#bypass`
](
http://docs.casperjs.org/en/latest/modules/casper.html#bypass
)
,
[
`Casper#thenBypass`
](
http://docs.casperjs.org/en/latest/modules/casper.html#thenbypass
)
,
[
`Casper#thenBypassIf`
](
http://docs.casperjs.org/en/latest/modules/casper.html#thenbypassif
)
,
[
`Casper#thenBypassUnless`
](
http://docs.casperjs.org/en/latest/modules/casper.html#thenbypassunless
)
methods
-
fixes
[
#410
](
https://github.com/n1k0/casperjs/issues/410
)
- trigger
`mousedown`
and
`mousedown`
events on click
-
Added
[
`Tester#skip`
](
http://docs.casperjs.org/en/latest/modules/tester.html#skip
)
method
-
Added
[
`Casper#eachThen()`
](
http://docs.casperjs.org/en/latest/modules/casper.html#eachThen
)
2013-02-08, v1.0.2
------------------
...
...
docs/modules/casper.rst
View file @
842e908
...
...
@@ -659,6 +659,21 @@ Iterates over provided array items and execute a callback::
Have a look at the `googlematch.js
<https:
//
github
.
com
/
n1k0
/
casperjs
/
blob
/
master
/
samples
/
googlematch
.
js
>
`_ sample script for a concrete use case.
``eachThen()``
-------------------------------------------------------------------------------
**Signature:** ``eachThen(Array array, Function then)``
Iterates over provided array items and adds a step to the stack with current data attached to it::
casper.start().eachThen([1, 2, 3], function(response) {
this.echo(response.data);
}).run();
.. note::
Current item will be stored in the ``response.data`` property.
.. _casper_echo:
.. index:: echo, Printing
...
...
modules/casper.js
View file @
842e908
...
...
@@ -567,7 +567,7 @@ Casper.prototype.download = function download(url, targetPath, method, data) {
/**
* Iterates over the values of a provided array and execute a callback
* for
@
item.
* for
each
item.
*
* @param Array array
* @param Function fn Callback: function(self, item, index)
...
...
@@ -588,6 +588,32 @@ Casper.prototype.each = function each(array, fn) {
};
/**
* Iterates over the values of a provided array and adds a step
* for each item.
*
* @param Array array
* @param Function then Step: function(response); item will be attached to response.data
* @return Casper
*/
Casper
.
prototype
.
eachThen
=
function
each
(
array
,
then
)
{
"use strict"
;
if
(
!
utils
.
isArray
(
array
))
{
this
.
log
(
"each() only works with arrays"
,
"error"
);
return
this
;
}
(
function
_each
(
self
)
{
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
self
.
then
(
function
()
{
this
.
then
(
this
.
createStep
(
then
,
{
data
:
item
}));
});
});
})(
this
);
return
this
;
};
/**
* Prints something to stdout.
*
* @param String text A string to echo to stdout
...
...
@@ -1353,6 +1379,7 @@ Casper.prototype.run = function run(onComplete, time) {
*/
Casper
.
prototype
.
runStep
=
function
runStep
(
step
)
{
"use strict"
;
/*jshint maxstatements:20*/
this
.
checkStarted
();
var
skipLog
=
utils
.
isObject
(
step
.
options
)
&&
step
.
options
.
skipLog
===
true
,
stepInfo
=
f
(
"Step %d/%d"
,
this
.
step
,
this
.
steps
.
length
),
...
...
@@ -1381,6 +1408,9 @@ Casper.prototype.runStep = function runStep(step) {
},
this
.
options
.
stepTimeout
,
this
,
new
Date
().
getTime
(),
getCurrentSuiteId
(
this
));
}
this
.
emit
(
'step.start'
,
step
);
if
(
this
.
currentResponse
)
{
this
.
currentResponse
.
data
=
step
.
options
&&
step
.
options
.
data
||
null
;
}
try
{
stepResult
=
step
.
call
(
this
,
this
.
currentResponse
);
if
(
utils
.
isFunction
(
this
.
options
.
onStepComplete
))
{
...
...
tests/suites/casper/steps.js
View file @
842e908
...
...
@@ -35,3 +35,17 @@ casper.test.begin('steps tests', 8, function(test) {
test
.
done
();
});
});
casper
.
test
.
begin
(
'eachThen() tests'
,
1
,
function
(
test
)
{
var
received
=
[];
casper
.
start
().
eachThen
([
1
,
2
,
3
],
function
(
response
)
{
received
.
push
(
response
.
data
);
});
casper
.
run
(
function
()
{
test
.
assertEquals
(
received
,
[
1
,
2
,
3
],
'Casper.eachThen() passes item to step data'
);
test
.
done
();
});
});
...
...
Please
register
or
sign in
to post a comment