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
214ed0c3
...
214ed0c3ad68506d7c6185faced72eed1ceedb89
authored
2011-10-16 00:26:42 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper#each() and Casper#getTitle() + example
1 parent
5a0a49ff
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
0 deletions
.gitignore
casper.js
samples/each.js
.gitignore
View file @
214ed0c
.DS_Store
*.xml
...
...
casper.js
View file @
214ed0c
...
...
@@ -231,6 +231,16 @@
return
this
.
exit
(
Number
(
status
)
>
0
?
Number
(
status
)
:
1
);
},
each
:
function
(
array
,
fn
)
{
var
i
=
0
;
(
function
(
self
,
i
)
{
array
.
forEach
(
function
(
item
)
{
fn
(
self
,
item
,
i
);
});
})(
this
,
i
);
return
this
;
},
/**
* Prints something to stdout.
*
...
...
@@ -378,6 +388,17 @@
},
/**
* Retrieves current page title, if any.
*
* @return String
*/
getTitle
:
function
()
{
return
this
.
evaluate
(
function
()
{
return
document
.
title
;
})
},
/**
* Logs a message.
*
* @param String message The message to log
...
...
samples/each.js
0 → 100644
View file @
214ed0c
phantom
.
injectJs
(
'casper.js'
);
var
links
=
[
'http://google.com/'
,
'http://yahoo.com/'
,
'http://bing.com/'
];
var
casper
=
new
phantom
.
Casper
();
var
i
=
0
;
var
titles
=
[];
casper
.
start
();
casper
.
each
(
links
,
function
(
self
,
link
)
{
self
.
thenOpen
(
link
,
function
(
self
)
{
self
.
echo
(
self
.
getTitle
());
});
});
casper
.
run
(
function
(
self
)
{
self
.
exit
();
});
Please
register
or
sign in
to post a comment