Selenium vs PhantomJS, CasperJS, or ZombieJS do almost the same thing, automate browsers, but why should you use one over the other? It turns out that there are some use cases when using Selenium might give you advantages over a headless toolkit.
I’m not saying that I always use Selenium. I prefer to use PhantomJS because it would have less overhead and performs better. However, because of specific edge cases I needed to use a real browser where the headless toolkit just didn’t cut it.
(This is a follow up post to Running Headless Selenium with Chrome.)
#1. Easier development with Inspect Element
While writing automation against other pages, I didn’t always know what HTML element I needed to write code for. So I would write code by using a UI, right clicking on some part of the page, then selecting the HTML element I wanted.
#3. When the website uses strange browser detection
An exmaple use case is scraping websites. I’ve found websites that give you slightly different HTML than they present a browser even after you change the
user-agent string. My guess is they also might attempt to detect HTML5 features or a Flash plugin.
From an SEO perspective the change in HTML it’s nothing that I would consider a negative or a cloak but the interesting bits I wanted weren’t there to scrape or interact with. A real browser was the only thing that worked for me.
#4. I actually need Flash
One of our features uses ZeroClipboard. It works partly by using an invisible Flash movie. So by default, I will need a real browser to make this test work.
#5. When you need a browser specific features
I have not used Selenium this way yet but I will need it soon. Some features I work on include steps that uploads files, print from the webpage, opens separate windows, switches tabs, and uses browser plugins.
Some features I work on right now include these steps. While we have those features covered in unit tests, I’m also testing them manually for important features. I anticipate this is a good way to automate those tests.
Again, I’m not saying that I always use Selenium. I only use it for specific use cases because it’s the only thing that will work.