PhantomJS + CasperJS Part I Installation

Task Automation and Testing

Starting Web Testing with PhantomJS and CasperJS

Casper with ES6 starting template

Requirement

  • NPM installed
  • Python installed

Installation

  • 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
console.log("test");

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();
console.log("Testing");
casper.exit();

Then run npm start or yarn start

Follow on to part II


profile image
Written by Lai Weng Han


5d21da44a24046755f76687aa470d3e6
Wow it looks amazing!
by Lai almost 2 years ago