Difference of Headless browsers for automation

Browser

A Browser is an application program that provides a way to look at and interact with all the information on the World Wide Web. Technically a Browser, alternatively referred as a Web Browser or Internet Browser, is a client program that uses HTTP (Hypertext Transfer Protocol) to make requests of Web servers throughout the Internet on behalf of the Browser User.


Headless Browser

A Headless Browser is also a Web Browser but without a graphical user interface (GUI) but can be controlled programmatically which can be extensively used for automation, testing, and other purposes.


Why to use Headless Browsers?

There are a lot of advantages and disadvantages in using the Headless Browsers. Using a headless browser might not be very helpful for browsing the Web, but for Automating tasks and tests it’s awesome.


Advantages of Headless Browsers

There is a lot of advantages in using Headless Browsers. Some of tham are as follows:

  • A definite advantage of using Headless Browsers is that they are typically faster than real browsers. The reason for being faster is because we are not starting up a Browser GUI and can bypass all the time a real browser takes to load CSS, JavaScript and open and render HTML DOM.
  • Performancewise you can typically see a 2x to 15x faster performance when using a headless browser.
  • While Scraping Websites you don’t necessarily want to have to manually start up a website. So you can access the website headlessly and just scrape the HTML. You don’t need to render a Full Browser to do that.
  • Lot of developers use a Headless Browser for unit testing code changes for their websites and mobile apps. Being able to do all this from a command line without having to manually refresh or start a browser saves them lots and effort.

When You Might NOT Want to Use a Headless Browser

There can be number of reasons why you may opt to use a Real Browser instead of a Headless Browser. A couple of instances:

  • You need to mimic real users.
  • You need to visually see the test run.
  • If you need to do lots of debugging, headless debugging can be difficult.

Which headless browsers are better?

As you rightly pointed that …the main difference is in the execution on GUI bases and non GUI bases(Headless)…, so from Testing Perspective a lot will depend on the Browser Engine implemented under the hood by any particular browser. For example, here are some of the Browser Engines which fully render web pages or run JavaScript in a virtual DOM.

  • Chromium Embedded Framework: CEF is a open source project based on the Google Chromium project with JavaScript support and BSD license.
  • Erik: Erik is a Headless Browser on top of Kanna and WebKit with Swift support and MIT license.
  • jBrowserDriver: jBrowserDriver is a Selenium-compatible Headless Browser which is WebKit-based and works with Selenium Server through Java binding support and Apache License v2.0 license.
  • PhantomJS: PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG with JavaScript, Python, Ruby, Java, C#, Haskell, Objective-C, Perl, PHP and R(via Selenium) support and BSD 3-Clause license.
  • Splash: Splash is a javascript rendering service with an HTTP API. It’s a lightweight browser with an HTTP API, implemented in Python using Twisted and QT with almost all the laungage binding arts and BSD 3-Clause license.

You can find a related discussion in Which drivers support “no-browser”/“headless” testing?

Leave a Comment