PhantomJS + CasperJS Part I Installation

Task Automation and Testing

Starting Web Testing with PhantomJS and CasperJS

Casper with ES6 starting template


  • NPM installed
  • Python installed


  • Method 1: Download PhantomJS
    • Download PhantomJS and make Alias to to the bin file
  • Method 2: Use PhantomJS with NPM
    • create a new directory
    • Initialize npm => npm init or yarn init
    • Install PhantomJS as Dependencies for CasperJS => npm install phantomjs-prebuilt --save or yarn add phantomjs-prebuilt

For both method, we still need to install CasperJS => npm install casperjs --save or yarn add casperjs

My version on time of posting:

"dependencies": {
    "casperjs": "^1.1.4",
    "phantomjs-prebuilt": "^2.1.16"

Test our built

create a file main.js

// main.js

For method 1, run phantomjs main.js

For method 2, create a script in package.json

"scripts": {
    "start": "./node_modules/.bin/casperjs main.js"

Then run npm start or yarn start

Then console will not stop until you exit (Ctrl+c)

Make CasperJS automatically close

var casper = require('casper').create();

Then run npm start or yarn start

Follow on to part II

profile image
Written by Lai Weng Han

Wow it looks amazing!
by Lai about 2 years ago