CasperJS Navigation scripting & testing for PhantomJS and SlimerJS

Install PhantomJS or SlimerJS, then:

npm install casperjs
node_modules/casperjs/bin/casperjs selftest
Other install options
5,605 Stargazers 896 Forks


Testing

CasperJS comes with a basic testing suite that allows you to run full featured tests without the overhead of a full browser. Output the tests to xunit for long term code health as well.


casper.test.begin('Hello, Test!', 1, function(test) {
    test.assert(true);
    test.done();
});

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

Scraping

Capture data from web pages simply that don't contain APIs. Validate your production environment on a regular basis. Alternatively, use this to load your application with data.


var casper = require('casper').create();
var links;

function getLinks() {
// Scrape the links from top-right nav of the website
    var links = document.querySelectorAll('ul.navigation li a');
    return Array.prototype.map.call(links, function (e) {
        return e.getAttribute('href')
    });
}

// Opens casperjs homepage
casper.start('http://casperjs.org/');

casper.then(function () {
    links = this.evaluate(getLinks);
});

casper.run(function () {
    for(var i in links) {
        console.log(links[i]);
    }
    casper.done();
});

$ casperjs query-casperjs.js
http://docs.casperjs.org/en/latest/quickstart.html
http://docs.casperjs.org/en/latest/
https://github.com/casperjs/casperjs
https://groups.google.com/forum/#!forum/casperjs
[...snip...]

Support Development