phantom.js

- A headless browser -

Contents

What is phantom.js

How to use it

Simple demos

case study

more demos

phantom.js

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

  • Headless website testing
  • Screen capturing
  • Page automation
  • Network monitoring
  • Command line util - easy integration to any CI tool
  • JavaScript :)
  • Bad documentation

phantom.js

Pros

Cons

Hello My phantom

Phantom can be run in your favourite shell on Windows, OS X or Linux.

 

phantomjs runner_script.js param1 param2 2000

 

All other parameters passed will be propagated to runner script.

Hello My phantom

Phantom has several modules that are used for automation and testing:

  • Web Page Module
  • Child Process Module
  • File System Module
  • System Module
  • Web Server Module

Concept similar to node.js, but modules can't be shared.

Web page Module

More or less everything needed for basic testing:

  • open
  • evaluate
  • render
  • viewportSize

DEMO TIME

testing

Phantom can be used with any testing framework, many of which already have runner scripts implemented available on PhantomJS web page.

 

Similar concept also has CasperJS, which is a wrapper around PhantomJS and adds testing APIs so no additional test frameworks are needed.

Case study: Testdome

Phantom.js was a natural way to go for testing HTML and JavaScript tasks. QUnit was chosen for simplicity, previous experience and community support (i.e. existent runner script :) ).

Problems:

  • Validating pure HTML/CSS tasks
  • Testing async JavaScript

Case study: Testdome

  • PhantomJS Runner QUnit Plugin was the solution for async tests.
  • For pure HTML tasks runner script needed to be modified to deal with JS injection.

Demo time

Thanks!

http://slides.com/djerbic/phantom-js/

 

http://phantomjs.org/

phantom.js

By djerbic

phantom.js

  • 1,142