top of page
Search
  • Writer's pictureSumit Mundhada

Headless Test Automation

Headless testing is a way of running tests without browser UI (without the head), no GUI of any sorts.

It is recommended to use Headless test automation in a CI environment because there is no point of running GUI flows especially when no one is watching, so there is no need to have the extra overhead of the browser GUI.

Headless browsers give you a fast, lightweight way to automate overall actions or flows. Headless browsers avoid draw operations. Draw operations handle rendering of the user interface with various pixels on the screen. With headless testing, we disable draw operations and the headless engines just run the same tests in the background without a need for a user interface making it faster.


Selenium with Java is very famous choice for many automation projects. So, Selenium supports headless testing using its class called HtmlUnitDriver. This class internally uses HtmlUnit headless browser

Pros of Headless browser:

  • Faster feedback to developers about basic and alternative flows

For basic level of sanity checks after every build you may use the headless browser

to run your tests.

  • Collect data from different pages – if no GUI validation is required.

  • Faster Automation

  • Get page response time

  • Take screenshots, reports.

  • UI Performance check before deployment

  • SSL Performance test

  • Simulate multiple browser versions on the same machine

You may find headless versions of popular browsers like Chrome and Firefox with

tools to simulate several different browsers.

  • Multitasking.


Cons of Headless testing:

  • No real user experience check.

  • Can’t be used to find UI defects such as the location, pixels of a web element, etc.


Popular Headless Browsers:

  • Google Chrome since version 59

  • Google Puppeteer- It is a Node library. It gives you a high-level API to control headless Chrome

  • Firefox versions 55 & 56

  • HtmlUnit – famous headless browser for Java programmer

  • PhantomJS – scriptable with a JavaScript API

  • Splinter –It is an open source, useful for testing web applications using Python.

As Selenium with Java is the most widely used automation tool, let’s check out how to configure it for using Headless browser testing. We will need a Global properties file to have an option for this feature.

Example: Brower property file will have such options.

browser=chrome

headless=true

Now for Selenium with Java – Let’s import relevant packages based on the browser.

For example, if you are using Chrome then you should import ChromeOptions.

That’s it, now use an API to enable headless – options.setHeadless(property file variable value)

If you want to change to UI mode – change property file value.

32 views
bottom of page