-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Headless Testing
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 as a continuous integration system.
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 |
Mocha | mocha-phantomjs |
FuncUnit | built-in |
Hiro | 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, United |
Testacular | built-in |
Testem | built-in |
WebDriver | GhostDriver |
wru | built-in |
YUITest | Grover, phantomjs-yuitest |
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
PhantomJS includes run-qunit and run-jasmine in its examples
subdirectory. However, these are for illustration purposes, it lacks important reporting features necessary for real-world uses.
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.