When comparing Selenium vs PhantomJS, the Slant community recommends PhantomJS for most people. In the question“What are the best multi-browser testing tools with synchronized interactions?” PhantomJS is ranked 3rd while Selenium is ranked 4th.
Ranked in these QuestionsQuestion Ranking
Pro Uses an approved WC3 standard - WebDriver
The WebDriver protocol is standardized by the World Wide Web Consortium which makes it easy for third-parties to get involved and contribute to Selenium.
WebDriver has been the foundation of many additional automation projects besides core selenium and has become the de-facto standard for UI automation.
Pro Integrates with any CI tool
Selenium, with its ability to interact with different testing frameworks, like NUnit or xUnit, makes it easy to get Selenium working with practically any Continuous Integration services.
Supports many browsers and a solid platform for adding future browsers to selenium (WebDriver)
Pro Actively supported
The open source community behind Selenium has a very large & engaged developer base. This ensures a stable support channel for the tool. In addition, various companies also provide support for Selenium. This active and multi-channel support provides a much more lucrative option for developers looking to implement Selenium in their workflow.
Pro You can use the same IDE you use for coding to debug
Pro Integrates well with existing testing frameworks
Pro Support for many languages
Selenium is based on Java and can be run on Windows, Mac, Linux, Unix, etc.
Pro Ability to imitate a real user using the application
Testing is analogous to a human being using the web application which is not possible with a solution which runs headless and claims to run faster than Selenium.
Pro Use the very minimum amount of code required to run
Selenium tries to inject into the page only the bare minimum of code needed to run the tests.
Pro Easy to set preconditions for the tests
Pro Supports screen capture
Pro Used in many open source projects
Pro Supports many browser standards
PhantomJS has full DOM and CSS parsing, JSON, canvas, and SVG support.
Pro Built on WebKit
WebKit is becoming the gold standard for browser compatibility, making it a good starting point for native headless browser testing.
Pro Active development
Development activity and number of contributors is healthy.
Con The IDE for recording isn't too powerful
Con Issues with locators
Locators that support common attributes like:
Con Browser closes unexpectedly
It often happens when running on more then 5 (my measurement) JVM instances that the browser gets stuck and quits unexpectedly. This can be partially solved by running the instances one by one instead of parallel (this is a problem when testing Jenkins and Bamboo agents) but I don't believe this qualifies as a solution. The error is called
Con Elements are sometimes not visible
This is an error which occurs with almost no reason, PhantomJS sometimes decides that it cannot click the element even though the element is intractable or enabled.
The error it raises is:
Con Heavy setup
You'll often end up having PhantomJS binaries connected via WebDriver to your testing framework, possibly using client/server especially if you want your test running with something else than Java. This mean an overhead in terms or maintenance and performance, but still usually lighter than running a full browser (like Chrome, Firefox, IE).