Acceptance Testing With PhantomJS and CasperJS

Home » Blog » Software » Front End Development » Acceptance Testing With PhantomJS and CasperJS

PhantomJS is a headless WebKit browser that allows you to call, test and scrape websites from the command line. In the developer’s own words:

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

CasperJS is a testing and scripting framework that builds on PhantomJS. Again, in the developer’s own words:

CasperJS is an open source navigation scripting & testing utility written in Javascript and based on PhantomJS — the scriptable headless WebKit engine. It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:

  • defining & ordering browsing navigation steps
  • filling & submitting forms
  • clicking & following links

In the past few weeks I’ve been using CasperJS for implementing automated acceptance tests for two web apps – one implemented with Apache Wicket and a Rails app – and CasperJS tests have proven to be a useful addition to unit and integration tests. By providing a JavaScript API for defining navigation scenarios it allows you test a web app just the way the user would see it. As CasperJS is a headless WebKit it can be run from the command line and hence can be integrated in continuous integration processes.

CasperJS makes implementing acceptance tests a breeze, which makes it a great tool for complementing your test suite. I’d even go as far as saying that for web applications acceptance tests can work as a replacement for traditional unit tests since they more accurately define the behaviour of an application.

Edit: I just found this article by Codeship.io about testing with CasperJS, which has some nice CasperJS code examples.

9 Comments
  1. Pingback: BromBone – Headless Browser As A ServiceBjörn Wilmsmann | Björn Wilmsmann

Leave a Comment

* Checkbox GDPR is required

*

I agree

By continuing to browse the site you agree to our use of cookies. Privacy Policy

Privacy Preference Center

Strictly necessary

These cookies are necessary for the site to function.

PHPSESSID: Preserves user session state across page requests.

__cfduid: Used by the content network, Cloudflare, to identify trusted web traffic.

PHPSESSID
__cfduid

Preferences

Remembers the user's submitted data when a comment is submitted in a blog post. The purpose is to aut o-populate form fields for subsequent comments, in order to save time for the user.

wfvt_#

Statistics

Statistic cookies help us to understand how visitors interact with our websites by collecting and reporting information anonymously.

_ga: Registers a unique ID that is used to generate statistical data on how the visitor uses the website.

_gat: Used by Google Analytics to throttle request rate.

_gid: Registers a unique ID that is used to generate statistical data on how the visitor uses the website.

collect: Used to send data to Google Analytics about the visitor's device and behaviour. Tracks the visitor across d evices and marketing channels.

_ga,_gat,_gid
collect

Security

We use Wordfence to secure our website against hacking attempts: https://www.wordfence.com/

wordfence_verifiedHuman

Close your account?

Your account will be closed and all data will be permanently deleted and cannot be recovered. Are you sure?