Key Differences Between Selenium and PhantomJS Being a headless browser, the interactions are much faster than the real browser. So the performance time is smoother in PhantomJS than in Selenium.
Selenium considers PhantomJS as deprecated, so you need to us either Chrome or Firefox in headless mode.
Headless Chrome is now the browser engine that the tests run against, instead of PhantomJS. This swap "just" replaces the browser with a newer, faster version with better support and upgrades. New versions of Headless will support changes in the definitions of CSS or the JavaScript compiler.
PhantomJS is a headless browser that can be used with the Selenium web automation module. Unlike the FirefoxDriver or ChromeDriver, the browser stays totally invisible during the process. It behaves just like the other browsers.
They are attacking different problems. Since PhantomJS runs perfectly on the command-line, it is suitable as the first layer of smoke testing, whether as part of development workflow and/or in a continuous integration server. Selenium targets multiple browsers and hence it is very useful to ensure cross-browser consistency and carry out extensive testings across different operating systems.
If your web application needs to run on a variety of web browsers, running the UI testing only with PhantomJS will not yield the most test coverage. However, it is perfectly fine to launch PhantomJS and exercise some basic sanity checks before doing the in-depth tests. Imagine the madness of testing a finance application where the login screen is unintentionally broken and non-functional!
Note that the line between the two gets slightly blurred with the recent WebDriver support in the latest PhantomJS. It is now possible to quickly run the tests first using PhantomJS and then (assuming there is no serious error encountered) continue to execute the same tests thoroughly in a Selenium setup.
With the recent WebDriver integration (as Ariya has noted), you can now use Selenium to drive PhantomJS.
This is immensely powerful.
You can run a set of fully automated Selenium tests (using PhantomJS as the WebDriver implementation) via your CI on a headless Unix server on every check-in. Then if you want to test browser compatibility you can run your tests locally by changing the underlying WebDriver implementation to Chrome, Firefox etc.
I am currently writing a web extraction framework. I have 524 tests that get data from 250 websites using XPath. Initially the framework used a HTML parser, HTMLCleaner, but I am currently investigating using Selenium because I want Javascript support. I have run the tests against the HtmlUnit, Chrome, Firefox and PhantomJS drivers. Here is a comparison of the time taken and the number of failures for each approach:
Failures Time (secs)
HtmlCleaner 0 82
HtmlUnit 169 102
Google Chrome 38 562
Firefox 46 1159
PhantomJS 40 575
Some comments:
In some cases the "failures" may not be failures at all, it may be that the extractors are failing because Javascript is re-writing the DOM. I am in the process of analyzing the failures to find the cause.
That said, HtmlUnit is the fastest Selenium driver but it is also unreliable. This unreliability does not just concern Javascript, there are problems processing "messy, dirty, real-world" HTML because something seems to be broken in the tag balancing algorithm. A couple of issues have been raised about this but they have not been fixed - see HTML-UNIT 1423 and HTML-UNIT 1046.
Firefox is the slowest Selenium driver, even though I am disabling image loading and stylesheets. This is because it is the slowest to load and initialize, making it considerably slower than Chrome, and every time an extraction fails I need to reload the driver (in the tests I create a pool of 5 drivers to mitigate the URL retrieval delays for all the Selenium web drivers).
PhantomJS achieves a better accuracy than Firefox, slightly lower than Chrome, but in around half the time of Firefox. What is more, I can run it on my dev box, it does not "take over my machine" by launching multiple browsers so I can get on with work.
I would highly recommend PhantomJS.
Leveraging the Power of Both Selenium and PhantomJS PhantomJS has the headless browser capabilities, hence it is good to use it as one of the browsers with selenium (In addition to traditional browsers like IE, Chrome etc.,) Advantages of this approach:
challenges I faced while using PhantomJS:
My Application was pricing web application:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With