Skip to content
ariya edited this page Mar 24, 2013 · 23 revisions

One major use case of PhantomJS is headless testing of web applications. It is suitable for general command-line based testing, within a precommit hook, and as part of a continuous integration system.

Test Frameworks

PhantomJS itself is not a test framework, it is only used to launch the tests via a suitable test runner.

The following table summarizes the list of various test frameworks and the corresponding test runners. If the framework does not need an external/third-party runner, it is marked as "built-in".

Framework Test Runner
Buster.JS built-in
Capybara Poltergeist, Terminus
Mocha mocha-phantomjs
FuncUnit built-in
Hiro built-in
Karma (née Testacular) built-in
Jasmine Chutzpah, grunt-jasmine-runner, guard-jasmine, phantom-jasmine
JsTestDriver js-test-driver-phantomjs
Robot Framework phantomrobot
QUnit built-in, Chutzpah, JS Test Runner, Qlive, QUnited
tapedeck built-in
Testem built-in
WebDriver GhostDriver
wru built-in
YUITest Grover, phantomjs-yuitest

PhantomJS includes run-qunit and run-jasmine in its examples subdirectory. However, these are for illustration purposes and lack important reporting features necessary for real-world uses!

PhantomJS tailored testing

In addition, there are projects which are built on top of PhantomJS to provide convenient high-level functionality for testing purposes:

  • Casper.js is useful to build scripted navigation and testing
  • Lotte adds jQuery-like methods, chaining, and more assertion logic
  • WebSpecter is a BDD-style acceptance test framework for web applications

Continuous Integration Systems

Using PhantomJS with CI system such as Jenkins or TeamCity does not require special setup. Make sure PhantomJS is installed properly on the slave/build agent and it is ready to go.

Since PhantomJS is purely headless on Linux, the agent can run on an installation with any GUI. This means, a barebone Linux system without X11 is not a problem for PhantomJS. It makes it possible to spawn light build agents on Amazon EC2 or Heroku instances.

Travis CI, a popular hosted CI system, has built-in support for PhantomJS. See its documentation for details.