introduction to phantomjs
TRANSCRIPT
lines
Introduction to
Console.log('Erol Seliektay');
Erol Selitektay
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.
Erol Selitektay
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.
Erol Selitektay
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.
Erol Selitektay
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.
Erol Selitektay
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 high-level 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.
Erol Selitektay
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 Settings3.Click Environment Variables... button4.Select Path in System variables and click Edit button5.Copy and Paste the location of phantomjs folder. Ex; in my case: C:\Users\erol\Tools\phantomjs-1.9.2-windows6. Click OK buttons.
Erol Selitektay
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!
Erol Selitektay
Examples
It captures screenshot with given width and height also get the page title.
Erol Selitektay
Examples
Erol Selitektay
This script shows the number of twitter followers for a specific account.
Thanks
For more information visit:https://github.com/ariya/phantomjs/wiki
Erol Selitektay