Skip to main content

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(),
    server = '',
    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.


Popular posts from this blog

the facebook breakup letter

dear facebook,

today marks our 10th year together, i must say it has been a sweet journey. unfortunately, time has come for me to walk away.

i had high hopes for us when we started, especially at the time when my heart still beat for… what was her name again? ahh friendster (may she rest in peace). but you were all smile and poised, a neatly uniformed college girl full of hopes and overflowing with excitement. you had me at one poke!

through you i bravely opened up my thoughts to the world. i was able to connect with old and new friends. you bridged time, the longitudes and the latitudes. i got found and new relatives were discovered. once a year you even make me famous sending out birthday reminders. with you, i was a kid in a playground, swiping up or down till the wee hours, unconditionally tagging anyone and gleefully enjoying your games.

know that i am glad to have witnessed you grow - your fun emojis, crazy virals, and live videos i will sorely miss. oh i always thought it’s cool…

16 Ways to Watch NBA Finals (Live Stream)

Facebook's Mark Zuckerberg Faces Congress

Facebook CEO, Mark Zuckerberg faced the senate judiciary and commerce committees today, in light of the recent data breach impacting over 87 million of its users.  
on march-21 addressing the cambridge analytica situation, "We have a responsibility to protect your data, and if we can't then we don't deserve to serve you. I've been working to understand exactly what happened and how to make sure this doesn't happen again. The good news is that the most important actions to prevent this from happening again today we have already taken years ago. But we also made mistakes, there's more to do, and we need to step up and do it," mark posted. 

here's a background of events;

as early as 2007 facebook envisioned that apps should be "social" enabling people to log into apps and share who their friends were and some of their information (birthdays, where they live, photos).  in 2013, a cambridge university researcher named aleksandr kogan created a perso…