2. What is
●
●
●
PhantomJS is a headless WebKit scriptable
with a JavaScript API.
Created by Ariya Hidayat. (http://ariya.ofilabs.com)
PhantomJS itself is NOT a test framework, it is
only used to launch the tests via suitable test
runner.
3. What Exactly Headless WebKit
●
●
WebKit is the layout engine that designed to
allow web browsers to render web pages.
Chrome, Safari and a couple of other browsers
also use WebKit.
Actually, PhantomJS is a browser but a
headless browser. This means that the
rendered web pages are never displayed.
4. Use Cases
●
●
●
●
Headless web testing. Lightning-fast testing without the
browser. Various test frameworks such as Jasmine,
Capybara, QUnit, Mocha, WebDriver, YUI Test, BusterJS,
FuncUnit, Robot Framework, and many others are
supported.
Page automation. Access and manipulate web pages with
the standard DOM API, or with usual libraries like jQuery.
Screen capture. Programmatically capture web contents,
including CSs, SVG and Canvas. Build server-side web
graphics apps, from a screenshot service to a vector chart
rasterizer.
Network monitoring. Automate performance analysis, track
page loading and export as standard HAR format.
5. Features
●
●
●
●
Multiplatform, available on major operating
systems: Windows, Mac OS X, Linux, other
Unices.
Fast and native implementation of web
standards: DOM, CSS, JavaScript, Canvas,
SVG. No emulation!
Pure headless (no X11) on Linux, ideal for
continuous integration systems. Also runs on
Amazon EC2, Heroku, Iron.io.
Easy to install.
6. Ecosystem
PhantomJS needs not be used only as a stand-alone tool.
Check also some excellent related projects:
●
●
●
●
●
●
CasperJS enables easy navigation scripting and common highlevel testing.
Poltergeist allows running Capybara tests headlessly.
Guard::Jasmine automatically tests Jasmine specs on Rails
when files are modified.
GhostDriver complements Selenium tests with a PhantomJS
WebDriver implementation.
PhantomRobot runs Robot Framework acceptance tests in the
background via PhantomJS.
Mocha-PhantomJS run Mocha tests using PhantomJS.
7. How to Download and Set Up
●
Go http://phantomjs.org/download.html
●
Download phantomjs-x.x.x-windows.zip
●
Unzip the folder
●
Set the path:
1.From the Desktop, right click Computer and click Properties.
2. Click Advanced System Settings
3.Click Environment Variables... button
4.Select Path in System variables and click Edit button
5.Copy and Paste the location of phantomjs folder. Ex; in my
case: “C:UserserolToolsphantomjs-1.9.2-windows”
6. Click OK buttons.
8. How to Run
●
Create a text file that contains the following
lines:
console.log('Radiohead is Awesome, by the way Hi World!');
phantom.exit();
●
Save it as hi.js
●
Run it from command prompt like this;
phantomjs hi.js
●
The output is:
Radiohead is Awesome, by the way Hi World!