Book Image

Getting Started with PhantomJS

By : Aries beltran
Book Image

Getting Started with PhantomJS

By: Aries beltran

Overview of this book

PhantomJS is a headless WebKit browser with JavaScript API that allows you to create new ways to automate web testing. PhantomJS is currently being used by a large number of users to help them integrate headless web testing into their development processes. It also gives you developers a new framework to create web-based applications, from simple web manipulation to performance measurement and monitoring.A step step-by by-step guide that will help you develop new tools for solving web and testing problems in an effective and quick way. The book will teach you how to use and maximize PhantomJS to develop new tools for web scrapping, web performance measurement and monitoring, and headless web testing. This book will help you understand PhantomJS’ scripting API capabilities and strengths.This book starts by looking at PhantomJS’ JavaScript API, features, and basic execution of scripts. Throughout the book, you will learn details to help you write scripts to manipulate web documents and fully create a web scrapping tool.Through its practical approach, this book strives to teach you by example, where each chapter focuses on the common and practical usage of PhantomJS, and how to extract meaningful information from the web and other services.By the end of the book, you will have acquired the skills to enable you to use PhantomJS for web testing, as well as learning the basics of Jasmine, and how it can be used with PhantomJS.
Table of Contents (13 chapters)
12
Index

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. The following are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The onLoadStarted event will be triggered when PhantomJS starts loading the page based on the resources received."

A block of code is set as follows:

var system = require('system');
var url = system.args[1];

var page = require('webpage').create();
page.onLoadStarted = function () {
  console.log('Page Loading Started');
};

page.onLoadFinished = function () {
  console.log('Page Loaded');
  phantom.exit(0);
};

page.open(url);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

Any command-line input or output is written as follows:

$ ./phantomjs pageload3.js http://www.google.com
Loading takes 6.751 seconds.
0.255 seconds : http://www.google.com/
0.379 seconds : http://www.google.com.ph/
0.213 seconds : http://ssl.gstatic.com/gb/images/b_8d5afc09.png
0.676 seconds : http://www.google.com.ph/images/srpr/logo1w.png
0.561 seconds : http://www.google.com.ph/images/srpr/nav_logo80.png
6.135 seconds : http://www.google.com.ph/xjs/_/js/hp/sb_he,pcc/rt=j/ver=_aDh7zAWqI8.en_US./d=1/sv=1/rs=AItRSTOgg467Qcx4GftzMMz3ZDPd84lcog

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes, for example, appear in the text like this: "Using a simple page open, handling these two events will give us two console prints: Page Loading Started which is displayed first, followed by Page Loaded."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.