Skip to content

@n1k0 n1k0 released this Jul 13, 2013 · 872 commits to master since this release

2013-07-13, v1.1-beta1

1.0 users, an upgrading guide is available here.

Important Changes & Caveats

Minimum PhantomJS version

PhantomJS 1.8.1 or later is required for 1.1.

Experimental support of Gecko, with SlimerJS

CasperJS can now be launched with SlimerJS instead of PhantomJS.
It allows you to execute tests with the rendering engine of Firefox. Just launch CasperJS
with the flag --engine=slimerjs.

SlimerJS 0.8 or later is required.

require() in custom modules

CasperJS 1.1 now internally uses PhantomJS' native require() function, but it has side effect if you write your own casperjs modules; in any casperjs module, you now have to use the new global patchRequire() function first:

// casperjs module code
var require = patchRequire(require);
// now you can require casperjs builtins
var utils = require('utils');
exports = {
    // ...

Note: you don't have to use patchRequire() in a standard casperjs script.

Testing framework refactoring

A new Tester.begin() method has been introduced to help organizing tests better:

function Cow() {
    this.mowed = false;
    this.moo = function moo() {
        this.mowed = true; // mootable state: don't do that
        return 'moo!';

// unit style synchronous test case
casper.test.begin('Cow can moo', 2, function suite(test) {
    var cow = new Cow();
    test.assertEquals(cow.moo(), 'moo!');

// asynchronous test case
casper.test.begin(' is navigable', 2, function suite(test) {
    casper.start('', function() {

    casper.then(function() {
    }); {

Tester#setUp() and Tester#tearDown() methods have been also added in order to ease the definition of operations to be performed before and after each test defined using Tester#begin():

casper.test.setUp(function() {
    console.log('executed before each test');

casper.test.tearDown(function() {
    console.log('executed after each test');

Both can work asynchronously as well of you define the done argument:

casper.test.setUp(function(done) {
    setTimeout(function() {
        console.log('asynchronously executed before each test');
    }, 1000);

casper.test.tearDown(function(done) {
    setTimeout(function() {
        console.log('asynchronously executed after each test');
    }, 1000);

Tester#begin() itself has also local setUp() and tearDown() capabilities if you pass it a configuration object instead of a function:

casper.test.begin('range tests', 1, {
    setUp: function(test) {

    tearDown: function(test) {
        this.range = [];

    test: function(test) {
        test.assertEquals(this.range.length, 3);

Scraping and testing are now better separated in CasperJS. That involves breaking up BC on some points though:

  • The Casper object won't be created with a test reference if not invoked using the casperjs test command, therefore the ability to run any test without calling it has been dropped. I know, get over it.
  • Passing the planned number of tests to casper.done() has been dropped as well, because done() may be never called at all when big troubles happen; rather use the new begin() method and provide the expected number of tests using the second argument:
casper.test.begin("Planning 4 tests", 4, function(test) {
    [1, 2, 3, 4].forEach(function() {

Last, all the casper test suites have been upgraded to use the new testing features, you may want to have a look at the changes.

Request abortion

When using PhantomJS >=1.9.0, you can now abort outgoing requests:

casper.on('page.resource.requested', function(requestData, request) {
    if (requestData.url.indexOf('') === 0) {

Bugfixes & enhancements

Assets 2
You can’t perform that action at this time.