Jump to ratings and reviews
Rate this book

Getting Started with Phantomjs

Rate this book
Harness the strength and capabilities of PhantomJS to interact with the web and perform website testing with a headless browser based on WebKit Overview In Detail 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. What you will learn from this book Approach A standard tutorial approach, as a complete guide detailing the major aspects of PhantomJS with particular focus on website testing. Who this book is written 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.

140 pages, Paperback

First published January 1, 2013

2 people are currently reading
113 people want to read

About the author

Aries Beltran

1 book2 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
6 (33%)
4 stars
6 (33%)
3 stars
5 (27%)
2 stars
1 (5%)
1 star
0 (0%)
Displaying 1 - 8 of 8 reviews
Profile Image for Marcus.
10 reviews2 followers
January 1, 2014
I was asked by Packt to review several books, but I chose "Getting Started with PhantomJS" because I was actually interested in it! I've used various faceless web browsers before, in particular webkit in GTK applications like wkhtmltopdf or with python or PHP bindings. wkhtmltopdf (and the related wkhtmltoimage) in particular has been suffering from neglect - it has lots of depedencies and it's difficult and unreliable to build and use (something I've written about before). I've most often used server-side browsers for tasks like generating page preview images, and seeing that phantomjs will do that, I've long thought I'd like to know more about it so that I could get away from custom-building complicated webkit stacks.

As far as I'm concerned, the two key things that phantomjs brings are a straightforward build process (a simple 'brew install phantomjs' for me) and a simple way of scripting the virtual browser, with the ability to inject scripts into the page, without having to resort to peculiar tricks, messing with virtual frame buffers or installing odd browser plugins.

I hadn't realised phantomjs's own scripting environment was quite so complete, supporting commonJS module integration. The separation between browser and page contexts (using `evaluate`) is clean and easy to get to grips with, and the book presents this well.

The book mentions several extensions to phantomjs that I had not encountered and look useful (particularly casper).

I hadn't spent much time reading phantomjs's own docs, but when I looked at them I found that they are very limited. Even though it's not long, the book goes deeper into examples and explanations than the docs, so there is genuine value in having the book.

All of the example code I tried worked without a hitch. Packt's web site sets a wrong MIME type on zip downloads, resulting in a page full of rubbish, but it unzips ok when saved manually. There are more example files than are mentioned in the book, which is a welcome bonus.

One small error I spotted suggested using single quotes around JSON values - that's not valid JSON, though it is valid Javascript. It also mischaracterises JSON slightly - object syntax is part of the Javascript language, so it's not a separate thing when you're already in a Javascript context.

One formatting issue costs a little typing - while all the code samples are provided as text and in files, all the displayed command lines (for example when a long URL is passed as a param) are in images, so you can't copy and paste commands as text. Call me lazy!

The English is generally good, concise and to the point. This is not a long book, but it doesn't need to be as a "getting started" guide on something that is a pretty confined subject. The editing had a few holes - several typos had sneaked through, things that would have been caught by any spell checker. The code samples had been updated recently, but there were no errata. Oddly, getting to errata is annoying on Packt's site - when you're looking at a book's page there is no link for it. You have to go to the "code and errata page" and select the book from the pop-up menu. This menu is sorted by the exact book title (and contains ALL their book titles!), so I had to look under 'getting...' rather than 'phantomjs'. This could be made much easier.

There are several other books and resources for learning and using phantomjs, and they may be sufficient for some users as it is a fairly small subject to cover. Overall I was impressed with the book. It does exactly what the title says, provides useful links for further reading, and provides effective, useful scripts that cover much of what many will want phantomjs to do in sufficient detail to make it easy to derive your own. Well done Aries!
1 review
February 12, 2014
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 :)

The book was 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.

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!

Read more of my review @ http://www.pilipinas.it.

You can purchase the book via http://www.packtpub.com/getting-start... or through Amazon.
1 review
February 10, 2014
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 PhantomJS

This 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. http://www.packtpub.com/getting-start...

1 review
February 12, 2014
Getting Started with PhantomJS

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.

http://www.packtpub.com/getting-start...
Profile Image for Andrew Artajos.
8 reviews1 follower
February 8, 2014
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 http://andoy.me
57 reviews
February 11, 2014
This wasn't bad. It's an intro book. Don't expect a lot of depth or a numerous examples. The examples that were present were interesting.

After reading this, I think it will be a stretch to put together something of medium complexity on your own.
Profile Image for Alvaro Tejada Galindo.
180 reviews5 followers
April 4, 2017
I would say...just go ahead and buy this book...I totally love it and will read it again just to discover and learn more....PhantomJS is just amazing!
Displaying 1 - 8 of 8 reviews

Can't find what you're looking for?

Get help and learn more about the design.