Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Should You Test Against PhantomJS?

DZone's Guide to

Should You Test Against PhantomJS?

With Google and Firefox's updates for native support for headless browsing and a lack of support for PhantomJS, this framework seems to be falling by the wayside.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

When you think of headless web application testing, you probably think about PhantomJS. PhantomJS has support for libraries a huge range of testing libraries, and being based on WebKit means that PhantomJS also has good support for the latest web standards, which has made PhantomJS a very popular choice for headless web app testing.

Recently, though, mainstream browsers like Chrome and Firefox have added native support for headless browsing. And we've been possible to run tests in headless Linux environments using tools like xvfb for quite some time.

So what does this mean for projects like PhantomJS?

Arguably the purpose of doing automated testing in a browser is to replicate and validate the end user experience. PhantomJS has been a good approximation of the end user experience, but no one will ever be browsing your website with PhantomJS.

It is also not a trivial task to construct tests that run reliably across multiple browsers. While PhantomJS is reasonably mature and battle-tested, there are always going to be some edge cases that you need to work around. Dealing with alerts is a good example of one of these edge cases, and so the decision to add PhantomJS as a test target should not be taken lightly.

But most significant is the fact that PhantomJS is not going to get much support from now on. One of the maintainers has stepped down, and there hasn’t been a new release in close to two years. Given how quickly web standards are evolving, along with browsers that have monthly release cycles, PhantomJS has slipped quite far behind the browsers your customers will actually be using.

Given PhantomJS is an unmaintained platform that no longer reflects the real end-user experience, and given that both Chrome and Firefox now support headless browsing natively, I would recommend not testing against PhantomJS. While PhantomJS was an excellent tool that filled a gap in the testing landscape a few years ago, today there are better options.

If you are interested in writing end-to-end tests against headless browsers, check out my project Iridium, which is a free and open source project on GitHub. The Iridium documentation talks about testing headless browser, and there is also a course on Udemy.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
iridium ,phantomjs ,web dev ,end-to-end testing ,browser testing

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}