Headless Testing with PhantomJS

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 Chutzpah, mocha-phantomjs
FuncUnit built-in
Hiro built-in
Karma (née Testacular) built-in
Jasmine Chutzpah, grunt-contrib-jasmine, guard-jasmine, phantom-jasmine
Laika built-in
Preamble built-in
phantom-assert built-in
QUnit qunit-phantomjs-runner, Chutzpah, Qlive, QUnited
Robot Framework phantomrobot
Rx Test Runner built-in
tape-run built-in
Testem built-in
Venus.js 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 Related Projects which are built on top of PhantomJS to provide convenient high-level functionality for testing purposes:

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 without 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.