Performance testing with PhantomJS

Tweet about this on Twitter0Share on Facebook2Share on Google+1Share on LinkedIn0

Couple days ago I tried to parse something from one web site. But, guess what, it’s written with bunch of java scripts and tools like wget or curl which I usually use for this not worked at all. That is because those tools will just grab non-processed html. Then I found out PhantomJS. Really powerful tool, actually it’s headless web browser which you can use in shell. Even better you can run it on EC2 instance or any other Linux machine. I thought, if this tool can load whole web page like a real web browser, why not to use it for performance testing. There are a lot of tools for this purpose, but on newer webpages which are full of pictures and java scripts those are really useless. Let’t get started with simple setup on Linux machine:

Installation on Ubuntu server:

You can test if tool works as expected:

If you get the version info everything is fine. To do some performance testing with PhantomJS here is simple get.js script which will load whole webpage and return processed html:

Also if you didn’t notice, it will skip Google Analytics (ga.js). You can remove this part if you want. To try it run:

At the end I came up with simple command that will send multiple requests at same time, 10 in this case and with Linux time command you will get how long it takes to process all of them:

With PhantomJS you can do simple performance testing of your site and you will get more realistic results than using tools like ApacheBench, JMeter or whatever you used before for this.

Tweet about this on Twitter0Share on Facebook2Share on Google+1Share on LinkedIn0
Posted in Testing and tagged , , .

Alen Komljen

I'm a DevOps/Cloud engineer with experience that spans a broad portfolio of skills, including cloud computing, software deployment, process automation, shell scripting and configuration management, as well as Agile development and Scrum. This allowed me to excel in solving challenges in cloud computing, and the entire IT infrastructure along with my deep interest in OpenStack, Ceph, Docker and the open-source community.