Getting Started with PhantomJS – A New Journey Begins! [Book Review]

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!
//Say Hello with PhantomJS 
console.log(‘Hello, world!’);
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.
//This is how to load a page in PhantomJS:
var page = require(‘webpage’).create();“”, function (status) {
     if (status === “success”) {
     } else {
         console.log(“Page load failed.”);

I find this book easy to read with only 121 pages, you can actually get done with 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. 
//Example using HTTP POST operation
var page = require(‘webpage’).create(),
    data = ‘universe=expanding&answer=42’;, ‘post’, data, function (status) {
    if (status !== ‘success’) {
        console.log(‘Unable to post!’);
    } else {

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 Local Search and Google Directions API (which made me realize 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!

You can purchase the book via or through Amazon.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s