Casperjs/PhantomJs vs Selenium

spirit3189 picture spirit3189 · Dec 31, 2012 · Viewed 62k times · Source

We are using Selenium to automate our UI testing. Recently we have seen majority of our users using Chrome. So we wanted to know - pros and cons of using PhantomJS vs Selenium:

  • Is there any real advantage in terms of performance, e.g. time taken to execute the test cases?
  • When should one prefer PhantomJS over Selenium?

Answer

Ariya Hidayat picture Ariya Hidayat · Dec 31, 2012

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.