Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Getting Started with PhantomJS
Getting Started with PhantomJS

Getting Started with PhantomJS: Harness the strength and capabilities of PhantomJS to interact with the web and perform website testing with a headless browser based on WebKit

eBook
€17.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Getting Started with PhantomJS

Chapter 1. Getting Started

PhantomJS is a new solution that provides headless testing of web applications. It is also a tool for dynamically capturing and rendering pages as images. It allows you to programmatically manipulate page content to control and change it to different forms. It can scrape websites and save important information to files. It will also provide you network-level information of your page and site resources. These are just a few of the functions that PhantomJS can do for us. It provides a fresh and a whole new way for web designers, testers, and developers to perform and create browser-based solutions.

PhantomJS uses QtWebKit as its core browser capability and uses the WebKit JavaScript engine for script interpretation and execution. Anything and everything that you can do in a WebKit-based browser (such as Chrome, Safari, and Opera browser) you can do with PhantomJS. It's more than just a browser because it supports web standards, such as CSS selector, DOM manipulation, JSON, HTML5 Canvas, and SVG; moreover, you can do some cool stuff such as performing file system I/O, accessing system environment variables, or even instantiating your own implementation of a web server daemon.

Downloading PhantomJS

Before we go through the features of PhantomJS, first we need to get our copy of the PhantomJS binaries. Typically, PhantomJS provides downloadable releases of binaries that are precompiled and packaged. You can choose from Linux, Mac OS X, and Windows precompiled packages. To download a copy, go to http://www.phantomjs.org/download.html.

Download your binaries based on your preference of operating system. After downloading, extract the binaries to any folder you desire. That's it! Your PhantomJS binary is ready to be used.

Tip

Add PhantomJS to PATH

Add the /bin folder of PhantomJS into your $PATH OS to make it easier when calling PhantomJS main binary. This allows us to call the binary anywhere without specifying the full path.

We will be using the Mac OS X version of PhantomJS throughout this book for running code examples. Don't worry if you are working on a different platform; the instructions are the same on all platforms.

Tip

Quick PhantomJS install on Mac OS X

As an alternative to downloading the precompiled binary, we can install PhantomJS using brew:

brew update && brew install phantomjs

For more information about brew, visit http://brew.sh/.

Building PhantomJS from source

You may also want to build your own binaries by compiling PhantomJS from source. Sources are hosted in the Github server at https://github.com/ariya/phantomjs.

Before you start downloading sources, you will need these tools installed on your workspace:

OS

Required development tools

Windows

Visual Studio 2010 or 2008 (Express edition)

git

Mac OS X

Xcode

git

Ubuntu/RHEL/CentOS Linux

gcc

gcc-c++

make

git

openssl-devel

freetype-devel

fontconfig-devel

The PhantomJS team is always trying to find the optimal way to build the sources, and the build instructions are frequently modified. To build PhantomJS properly, you must follow the steps found here: http://phantomjs.org/build.html.

If you are not planning to hack into PhantomJS code and develop new features, then it is best to download the pre-packaged binaries.

Working with PhantomJS

Now, let's see how PhantomJS's magic works. It is a command-line-based application, so we need to execute it in an OS terminal or console. The PhantomJS package contains a series of files and comes with one main executable file, which is named phantomjs.

Open your terminal and then navigate to your PhantomJS bin folder. In the prompt, execute phantomjs without any arguments.

Tip

PhantomJS Windows build

In Windows build, PhantomJS executable can be found in the root folder with the filename phantomjs.exe.

Working with PhantomJS

Running PhantomJS without any arguments will give you an interactive prompt that is similar to the JavaScript debug console you could find in any modern browser. In this interactive prompt, we can execute JavaScript code line by line. This functionality is very useful for debugging or testing code before you actually build your script.

Say "Hello Ghost!" to PhantomJS using the interactive prompt. Using console.log will output any type of data to the output console of a JavaScript interpreter.

phantomjs> console.log("Hello Ghost!")
Hello Ghost!
undefined
phantomjs>

See? It is simple. Just like coding any JavaScript. But wait. What is that undefined message just after the Hello Ghost! message? That is not an error. It is just how the interactive mode behaves. Each call is expected to return data just like any ordinary function call and it also automatically outputs the data value to the output stream.

Since the console.log command does not return any value, the message is undefined. If we issue an assignment to a variable command, the following output will be displayed:

phantomjs> name = "Tara"
{}
phantomjs>

The assignment to a variable will take place and the result of the operation will be displayed. Because it is in the form of a string literal, the undefined message will not be displayed. The interactive mode is similar to a long-running script; any variable or function you define will be loaded into the memory buffer and can be accessed anytime during the session. So, based on our preceding example, the name variable can also be displayed by referencing it.

phantomjs> name = "Tara"
"Tara"
phantomjs> name
"Tara"
phantomjs> name + " and Cecil"
"Tara and Cecil"
phantomjs>

We can even use the variable with another operation as seen in the preceding lines of code. However, any operation's result that is not assigned to a variable will be available only during the execution of the line. The operation that concatenates the name variable with another string literal will be performed, and the resulting string will be displayed in the console but will not be kept in memory.

Objects can also be accessed within the interactive mode, and one of the most commonly used objects is phantom. Try typing phantom in the prompt and you will get the following output:

phantomjs> phantom
{
   "clearCookies": "[Function]",
   "deleteCookie": "[Function]",
   "addCookie": "[Function]",
   "injectJs": "[Function]",
   "debugExit": "[Function]",
   "exit": "[Function]",
   "cookies": [],
   "cookiesEnabled": true,
   "version": {
      "major": 1,
      "minor": 7,
      "patch": 0
   },
   "scriptName": "",
   "outputEncoding": "UTF-8",
   "libraryPath": "/Users/Aries/phantomjs/bin",
   "defaultPageSettings": {
      "XSSAuditingEnabled": false,
      "javascriptCanCloseWindows": true,
      "javascriptCanOpenWindows": true,
      "javascriptEnabled": true,
      "loadImages": true,
      "localToRemoteUrlAccessEnabled": false,
      "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X)AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.7.0Safari/534.34",
      "webSecurityEnabled": true
   },
   "args": []
}
phantomjs>

PhantomJS displays the content of the object when used in the interactive prompt, and even its own phantom object can be referenced. You may also observe that the object is displayed in the form of JSON and details every attribute of the object except for the function definition. Using this approach, we can also examine each and every object, and we will be able to know what the exposed attributes and available functions are.

Let's try using one of the most important functions available in the phantom object: the exit() function. This function will enable us to quit PhantomJS and return to the caller or to the underlying operating system.

phantomjs> phantom.exit()
$

This function signals the application to exit with a return code of zero or normal and without errors. Passing a numeric value as an argument of the exit() function denotes the error code to be passed back to the caller. This is helpful when trying to write scripts that need to verify if the execution was successful or if an error occurred and what type of error it was.

If we trap the error code in a shell script, it will look as follows:

#!/bin/bash
bin/phantomjs
OUT=$?
if [ $OUT -eq 0 ];then
   echo "Done."
else
   echo "Ooops! Failed.!"
fi

In the preceding lines of code, right after calling phantomjs, we capture the error code coming from the application using the $? function. We assign that to an OUT variable and then perform a test on it in the succeeding lines. If the error is equal to zero, then we display Done; otherwise, we say that the call failed.

$ ./trapme.sh 
phantomjs> phantom.exit(0)
undefined
Done.
$ ./trapme.sh 
phantomjs> phantom.exit(1)
undefined
Ooops! Failed.!
$

Use the interactive mode to experiment with the PhantomJS API.

Before we begin creating PhantomJS scripts, we first need to make a quick roundup of the PhantomJS JavaScript API.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

PhantomJS JavaScript API

PhantomJS runs JavaScript and comes with a JavaScript API to make your life easy. It extends the standard JavaScript API and adds richer layers of capabilities, such as allowing us access to the underlying file system, ease of access and manipulation of DOM objects, system and environment variable gathering. It even gives us the ability to inject custom scripts into the web page.

But, be warned. PhantomJS is a very active community, and every now and then, changes are being introduced. New APIs and objects are being added, but of course, there are few items that are being changed, and ultimately some of them become deprecated or are totally removed. The PhantomJS website has a full list of all the functions and syntax, and has proper tagging for deprecated functions. We should visit it regularly to check for upcoming updates so that we can adjust appropriately in our codes.

The Module API

While writing custom objects and API sets, you may want to create custom modules that will make your life easier. You can do that in PhantomJS using the Module API. It allows you to create your own modules and import it anywhere in your implementation. The built-in modules are webpage, system, fs (File System), and webserver.

The WebPage API

PhantomJS is a headless browser. Accessing and manipulating web documents are its core functionalities, and that's what the WebPage API is used for. The WebPage API allows us to access, control, and manipulate web documents. It provides a rich interface to easily reference and extract page details including document content. It enables capturing of events, such as page loading, when an error occurs within the page, or when navigating to another page is requested, and so on. It is also capable of capturing pages and saving them as images. And more importantly, it allows you to manipulate documents on the fly and traverse DOM as you do with any web page. This is enormously valuable for writing automated user interface tests—for example, you can force click events or post forms, and capture the results—as well as standard web scraping of public URLs.

The System API

The System module provides system-level functionalities ranging from OS information, environment variables, command-line arguments, and process-related properties. The System module is very useful as you engage more in developing applications with PhantomJS.

The FileSystem API

Accessing files, writing to text files, or just reading a custom configuration file—these are tasks that can be done with PhantomJS. FileSystem provides a standard API to perform file I/O. You can read, write, and delete files; you can even list folder files.

FileSystem has 31 functions to manage and manipulate files within PhantomJS. We have been using this set extensively, and it helps solve several problems without fail. Writing JSON data to a file is very basic, but you will find it much easier using the FileSystem API.

The WebServer API

Perhaps you have a grand idea, but it requires you to process a web request and execute a PhantomJS script on it. PhantomJS can do that; you can embed your own web server implementation using the WebServer API within your PhantomJS application. This feature is marked as experimental, but it does work, and with roughly five lines of code you can have your own web server running.

This module is based on the open source Mongoose web server library that supports multiple platforms, authorization, web sockets, URL rewrite, and even "resumeable" downloads. For more information about Mongoose, visit http://code.google.com/p/mongoose/.

The phantom object

The phantom object is your reference to PhantomJS within your scripts that allows you to access certain properties and provides functionality that affects the entire script (such as quitting the application as previously mentioned.) The phantom object can be directly referenced anywhere in the script and does not need to be explicitly imported. You may also access it as a child of the global window object.

The phantom object allows access to relevant data, such as cookies and library paths. If we want to import or inject third-party JavaScript libraries, such as jQuery, we can do that using the phantom object. We can also create a "catch all" event handler for errors using the onError event of the phantom object.

PhantomJS not only allows us to harness the power of JavaScript but also gives us a very useful API. Each day, more and more contributors are enhancing this API, giving us more options and easier ways to solve real problems. We will learn more about these APIs as we continue our journey learning about PhantomJS.

The command-line arguments

There are a few command-line arguments that we need to understand before plunging into writing PhantomJS scripts. The syntax of the PhantomJS argument is:

phantomjs [switches] [options] [script] [argument [argument [...]]]

All of the arguments are optional. Using the command without arguments will bring up the interactive mode.

The script argument

The script argument is the name of a script file. It can be a relative or an absolute path and must follow the path convention of the host system OS.

phantomjs /scripts/chapter1.js

The script filename may or may not end with a .js extension. PhantomJS supports two types of scripting—JavaScript or CoffeeScript. We don't need to specify if the script is in JavaScript or CoffeeScript; PhantomJS will automatically detect it. We will be using JavaScript in our examples. If you want to learn more about CoffeeScript, you may visit the CoffeeScript website at http://www.coffeescript.org.

The debug option

The debug option enables the printing of additional warnings and the debug messages. This is very useful when debugging your script. It accepts either yes or no as the value of the option, and no is the default value.

phantomjs --debug=yes /scripts/chapter1.js

The cookie-file option

If you are working on pages that require persistent cookies, you need to enable this option. This option will accept a file path where cookies will be saved and read.

phantomjs --cookie-file=/scripts/cookies.txt /scripts/chapter1.js

Writing PhantomJS scripts

We know how to write JavaScript, and now we know that there are several PhantomJS JavaScript APIs and objects. We also have learned the basics of the PhantomJS command-line arguments. We are now ready to create our own scripts.

We will create a simple script to load a site and then display the title of the page when loaded successfully. Finally, we will exit. If the page fails to load, we will log some message to the console.

var page = require('webpage').create();
page.open("http://www.packtpub.com", function(status) {
   if ( status === "success" ) {
      console.log(page.title); 
   } else {
      console.log("Page failed to load."); 
   }
   phantom.exit(0);
});

The preceding PhantomJS script is very simple. First, we import the webpage module, create an instance of the webpage object, and assign it to a variable named page.

The page variable now holds an instance of the webpage module where an open function is available. Next, we instructed PhantomJS through the webpage instance to open and load the URL. The second parameter of the open function is a function callback definition that will be executed upon completion of the opening of the URL. Inside the definition, we check if the status is "success", and if it is, the page is loaded, and then we will display the title of the page. Then, we call the exit function to terminate the script. Let's save this code snippet as helloweb.js and execute it by passing the filename as our first argument to the phantomjs binary.

Writing PhantomJS scripts
Left arrow icon Right arrow icon

Key benefits

  • Writing scripts that can interact directly with web services and pages
  • Interacting with social media websites using PhantomJS scripts
  • Creating web-based test scripts and running them in a headless browser

Description

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.

Who is this book for?

If you are a JavaScript developers who is interested in developing applications that interact with various web services, using a headless browser, then this book is ideal for you. This book will also be good for you if you are planning to create a headless browser testing for your web application. Basic understanding of JavaScript is assumed.

What you will learn

  • Explore the possibilities of PhantomJS development and make use of a headless browser
  • Understand PhantomJS’ core features and API
  • Manipulate the DOM properties of web pages using scripts
  • Interact with web pages using PhantomJS scripts
  • Learn how to emulate keyboards and mouse actions
  • Work with geolocation services with PhantomJS
  • Build scripts that will create web sites snapshots
  • Create and implement PhantomJS custom modules
  • Use PhantomJS to perform headless testing with Jasmine

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 25, 2013
Length: 140 pages
Edition : 1st
Language : English
ISBN-13 : 9781782164234
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 25, 2013
Length: 140 pages
Edition : 1st
Language : English
ISBN-13 : 9781782164234
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 96.97
Data Visualization with D3.js Cookbook
€36.99
PhantomJS Cookbook
€34.99
Getting Started with PhantomJS
€24.99
Total 96.97 Stars icon

Table of Contents

12 Chapters
1. Getting Started Chevron down icon Chevron up icon
2. Manipulating Page Content Chevron down icon Chevron up icon
3. Handling Events and Callbacks Chevron down icon Chevron up icon
4. Capturing Errors Chevron down icon Chevron up icon
5. Grabbing Pages Chevron down icon Chevron up icon
6. Accessing Location-based Services Chevron down icon Chevron up icon
7. Working with Files Chevron down icon Chevron up icon
8. Cookies Chevron down icon Chevron up icon
9. External JavaScript Chevron down icon Chevron up icon
10. Testing with PhantomJS Chevron down icon Chevron up icon
11. Maximizing PhantomJS Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(5 Ratings)
5 star 80%
4 star 20%
3 star 0%
2 star 0%
1 star 0%
SetITGood Feb 09, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Being in IT for almost two decades now I am perhaps lucky to have witnessed the growth of this industry. More so, I am glad to see the "rebirth" of Java Scripting for front-end development in the recent years. But ask any front-end developer and one thing they dreaded most was testing these web pages and Java Scripts. PhantomJS - however is a game changer!PhantomJS provides "headless" testing of web applications. Wait, what did I mean with headless? When you are typing a URL from the browser, it essentially creates a request and the response is reflected on the page. PhantomJS actually does the same thing, EXCEPT we don't need to wait for it to be rendered before our eyes! Probably this is how it got its name :)PhantomJS also can dynamically capture/render pages as images, allow manipulation of page content/event, gain access to network-level information, and ability to save important infos into files for later processing.I find this book easy to read with only 121 pages, you can actually finish it in one sitting (but would be good to do it in front of your laptop trying out the sample codes yourself). However, it is advised you already have concrete knowledge of Java Scripts, HMTL, and CSS since the book heavily used later technologies such as DOM, JSON, and HTML5.An improvement I guess would be since the goal of the book was to jumpstart IT practitioners into PhantomJS, it would have been better to have laid out the different syntaxes of PhantomJS itself. In Chapter 2, I was surprised to see "===" as the conditional operator. Having used to "==" in Java, I had to check this if it was a typo.The book has more to give than what I expected. All throughout, the book used actual web pages (e.g. Pinterest, Instagram) as examples for us to run our tests, which challenges our creativity and encourages us to further try it out with other pages. Aside from PhantomJS, I liked how in a subtle way, the author introduced other technologies such as Yahoo LocalSearch and Google Directions API (which made me realized how easy it was to use them!). In the last chapter, the book introduced CasperJS - a spin-off extension and further simplified PhantomJS. I find this really exciting!The book is concise and straightforward, I highly encourage everyone doing front-end development to read this and for Technical Architects to consider PhantomJS at production work.On a side note, I noticed that the author used his family member's names all throughout the book, so I guess this was in some way a personal book. Anyway, I am excited for PhantomJS and is looking forward to further playing with it!
Amazon Verified review Amazon
Bill Mar 30, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book. I had so much pleasure reading it and harness the power of phantomjs. Having a limited time for a project, i couldnt find much info about it even on their main site. This book provided an easy to follow guide. I recommend it!
Amazon Verified review Amazon
Geomar Esmilla Feb 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Getting Started with PhantomJS is a book about well, getting started. My work for the past 5 years requires me to review application architecture and data protection solutions, needless to say I have not coded in years. And this book just got me started writing codes again. You see, it really gets you started.There are very few books on web development tools these days that could capture my interest and maintain my interest. This book? I like this book. I like the way it's written. You should buy a copy and read it. Why? Because it starts and ends the way I like it. From introducing you to the command line interface (really for geek in all of us who loves that legacy look) and it ends with a shortlist of cool tools that will keep your momentum going.Aries Beltran writes that way that makes me reminisce those moments reading Borland books back in the 80s and 90s. Ahh.. Nostalgia. Simple, and effective in catching the reader's interest as one flips from page to page. This is a 140-page book. It's not long like those 5 inches thick book. But I'm impatient. I thought I'm going to speed read my way through it because I just don't have the patience, but I was wrong. It got me engaged enough to read, really read it from cover to cover. Every 11 chapter provides a newbie to PhantomJS like me a "Eureka" moment. I found myself immerse in Aries Beltran's world. I coded while reading. I coded while I ate (I especially loved Chapter 8: Cookies). And I coded in my sleep. And discovered that I like PhantomJS.The book is packed with cool recommendations:* Check out Confess.JS for metrics (a topic close to my heart)* CasperJS seems like a natural progression from PhantomJSThis book is basically good stuff. It's a book you will revisit again and again. It's a good addition to any developer's and web aficionado's library.Check them out. [...]
Amazon Verified review Amazon
Robert Y. De Cruz Feb 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
PhantomJS makes website UI testing easy. It can be used as an automation tool for repeatedly going through each page, providing a means for testing that a code commit didn't break the website. Full-time testers can use it to automate their work by setting up the test scripts once, then letting PhantomJS do the tedious work of re-running the script every time the same functionality needs to be tested. This is the way UI testing should be done and I wish we had a similar tool/framework for non-Webkit browsers and desktop apps.This book is an excellent tutorial to PhantomJS. After going through the book, I'm able to do simple tasks such as opening web pages, triggering UI elements, etc. Then it shows me how to do the more complex stuff such as taking a screenshot of a web page when it was accessed, reading cookies, and doing unit testing. Software Testers will find this book valuable to their job as it goes through all the functionality you'll need to test most websites. This book will also be useful for Software Devs aiming to add some UI-level unit testing to make sure markup and JS changes don't break any of the existing UI functionality. This is a must-have book for any web development project.I also found the book to be a good reference manual as it's designed to be easy to look up how to do things. The example scripts are simple to follow and can be readily incorporated in your test scripts. It's a valuable tool in the tester's arsenal. Highly recommended for website testers and web developers looking for an easier way to test and automate their web scripts.[...]
Amazon Verified review Amazon
Andrew Artajos Feb 08, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
At 140 pages and 11 chapters, this book is a quick read. To be honest it looks more like a booklet than a real book. Despite its appearance, it delivers the meat on the chosen subject--Getting started with PhantomJS.It starts you off on basic tasks like installing PhantomJS, working with the commandline, then moves toward the more complex tasks. The author shows you how to download a simple webpage then slowly builds upon this foundation in the succeeding chapters, until you get to learn how to use PhantomJS with different API's, JQuery, Jasmine--a unittesting framework, and CasperJS. There were some parts of the book I rather skip like Capturing Errors, Working with Files, and Cookies. These topics are boring but necessary nonetheless.The book is clear, concise, and uses simple English. This helps the reader go through the book quickly without having to put more effort in understanding the subject.The book in paperback format, although more expensive, is easier to read than the ebook format. When working with the examples, I think it would be more practical to buy the ebook instead. It will be easier to refer to when typing the actual code on the computer.However, this book makes you want more. I want to see in the future a more in depth take on PhantomJS. Most likely a book that discusses the best practices and some programming gems on the topic.Overall, this book is quite informative. It gets your feet wet on PhantomJS. I'm surprised that PhantomJS could open up to a lot of possible avenues to explore. PhantomJS when combined with modules, API's, and other open source software, offers a rich set of building tools for creating the next kick ass browser based solution.as seen on [...]
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.