PhantomJS - a powerful testing tool

PhantomJS is a headless WebKit for JavaScript that provides quick and native support for several web standards.

PhantomjsPhantomJS is a headless WebKit that provides quick and native support for several web standards. This powerful tool is scriptable with a JavaScript API and allows pages manipulation,  webpage capturing, access to the page settings and file system. Also PhantomJS emulates mobile Webkit, thus supports touch events.

Headless web testing with JavaScript

PhantomJS is mainly used for a headless testing of web applications. It is suitable for both general command-line based testing and as a part of a continuous integration system. It is important to remember that PhantomJS itself is not a testing framework, it is only employed to launch the tests via a suitable test runner.
PhantomJS is a headless WebKit. This means that it provides the layout engine similar to those that are used by Chrome, Firefox, Safari, or other niche browsers. Basically PhantomJS is a browser itself, though a headless one, where pages are never actually displayed.
PhantomJS code aims at controlling browser automation at high level. Although it is not a testing library, many other widely used testing libraries can run on top of PhantomJS, including Mocha, Jasmine, WebDriver, Capybara, FuncUnit, QUnit, Robot Framework, YUI Test, BusterJS, etc. In situation when the framework does not need an external runner, it is marked as "built-in".
Among PhantomJS advantages are:

  • Page automation. It is easy to load and manipulate web pages with the standard DOM API, or with usual libraries like jQuery.
  • Screen capture. Since PhantomJS uses a real layout and rendering engine, it can be used to capture web contents, convert it not only in HTML and CSS, but also into SVG and Canvas, and build server-side web graphics apps, from a screenshot service to a vector chart rasterizer.
  • Network monitoring. PhantomJS permits the inspection of network traffic and it is possible to automate performance analysis, track page loading and export as standard HAR format.
  • PhantomJS testing. Since it is possible to access and manipulate web pages with PhantomJS, it is suitable to carry out various page automations. Moreover, there are projects which are built on top of this WebKit in order to provide useful high-level functionality for testing purposes, e.g. Casper.js (convenient to build scripted navigation and testing), Lotte (contains jQuery-like methods, chaining, and more assertion logic), WebSpecter (BDD-style acceptance test framework for web applications).
  • Continuous Integration. Support and integration with the CI systems (e.g. Jenkins, TeamCity) does not demand special setup, since PhantomJS is purely headless on Linux and the agent can run on an installation with any GUI.

Ember.js, Bootstrap, CodeMirror, Zepto, Modernizr, Grunt, YUI3 are already using PhantomJS as a part of the testing workflow. Visit PhantomJS homepage for more information.
Contact Quintagroup if you want to improve your web application by testing it against different environments and we will provide qualified consulting and services.

Connect with our experts Let's talk