CasperJS is a navigation scripting & testing utility for the PhantomJS (WebKit) and SlimerJS (Gecko) headless browsers, written in Javascript.
It’s easy to install and easy to start!

var casper = require('casper').create();
casper.start('', function() {

Run it:
casperjs sample.js

we created a new Casper instance
we started it and opened
once the page has been loaded, we asked to print the title of that webpage (the content of its title tag)
we executed the whole process

CasperJS is also a testing framework; test scripts are slightly different than scraping ones, though they share most of the API.

A simplest test script:

casper.test.begin("Hello, Test!", 1, function(test) {

Run it using the casperjs test subcommand:
casperjs test hello-test.js

Test file: hello-test.js
#Hello, Test!
PASS Subject is strictly true
PASS 1 test executed in 0.023s, 1 passed, 0 failed, 0 dubious, 0 skipped.

CasperJS makes an heavy use of selectors in order to work with the DOM, and can transparently use either CSS3 or XPath expressions.

The tester module
CasperJS can export the results of the test suite to an XUnit XML file, which is compatible with continuous integration tools such as Jenkins. To save the XUnit log of your test suite, use the –xunit option:
casperjs test googletesting.js –xunit=log.xml

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someonePrint this page