Commit 214ed0c3 214ed0c3ad68506d7c6185faced72eed1ceedb89 by Nicolas Perriault

added Casper#each() and Casper#getTitle() + example

1 parent 5a0a49ff
.DS_Store
*.xml
......
......@@ -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
......
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();
});