Headless Browsers Testing using Selenium Webdriver

A beginner’s guide to driving headless browser testing Selenium is one of the most popular web automation tools in software testing today. Its ease of use, along with its adaptability to write tests in almost all popular programming languages makes it an ideal choice for programmers

and QA engineers. With Selenium WebDriver, one can open browser/s with URL, click a link, check URL, assert functions and so on.

However, sometimes, there are cases which may require the Automation Scripts to run in ‘Headless’ mode, i.e. when no browser is being displayed. In such cases, Selenium tests can be executed in headless browsers. Generally speaking, headless browsers find their use in testing usability and browser interactions. Vatsa Solutions has closely monitored this evolution of headless browsers and successfully implemented its use in real-time projects for long now.

What is Headless Browser?

A Headless browser means a browser which has NO Graphical User Interface (NO GUI). It is a browser simulation program that works like a regular browser, has all the functionalities of a browser, except for the user interface or display. When Selenium tests are run, it executes in the background.

Several such headless browsers are readily available in the market. The following are the most popular ones amongst developers –

  • Headless Chrome (Chrome 59 and above)
  • PhantomJS
  • SlimerJS
  • TrifleJS
  • HTMLUnit driver

Advantages of Headless Browser Testing

Since Headless browsers, do not have a GUI, they save a lot of resources and time. Following are some of the biggest advantages of headless browser testing:

  • Improves speed and performance – Since this type of testing does not actually open a browser, the system saves the processing power that would be used in a real browser test. Due to this, the tests are executed faster.
  • Allows testing browser-less setups – There may be setups where installing a browser is not possible, such as servers. In these cases, headless browsers help run automation tests easily.
  • Makes multi-tasking possible – One can use the browser or machine to continue doing other work, while the tests run in the background. This saves a lot of hours that is, otherwise, spent staring at the screen.
  • Minimum Human Intervention – There are fewer chances of failure and reduced errors due to minimum ‘human intervention.’
  • Taking Screenshots is Possible – Any desired screenshots are still stored, just like in regular automation testing.

Disadvantages of Headless Browser Testing

Running tests on headless browsers do have a few disadvantages. Some of them are as follows:

  • Lacks Actual User Experience

– Running headless tests cannot give real feel and experience. One cannot really mimic the real user experience.

  • UI issues can’t be identified

– Cosmetic bugs can’t be identified while doing headless browser testing. Issues like the location of a button or color of a web element, etc. cannot be identified.

  • Hard to debug inconsistent failures

– When it comes to debugging, headless browsers may not be the best option to find out Inconsistent errors and failures.

Limitations

  1. Until recently, modern browsers like Chrome and Firefox did not offer any built-in support for running their browsers in Headless mode. QA engineers would use open-source headless browsers such as PhantomJS or Zombie JS to achieve this purpose. However, much-awaited headless mode is made available, for Chrome 59 and Firefox 56 versions and higher.
    Rendering: User could not feel how UI is rendering.
  2. Resizing & page height: User cannot resize the page in headless testing.
  3. User cannot use IE10, IE11, Edge, Opera & Safari for headless testing.

Running Selenium Tests in Headless Google Chrome

Google recently introduced a headless option for Chrome. It is available from version 59 onwards. However, before testing begins, there are a couple of things which need to be installed first

  1. Java
  2. Selenium
  3. ChromeDriver (latest)

ChromeOptions is a class in Selenium to set the arguments to ChromeDriver.

To understand better how a program works in headless mode, we can see it from a sample program. In the following example, we will pass the one argument to ChromeDriver to run in headless mode.

If the above code is run, it will print the title of the page and will take the screenshot as well. (See screenshot below).

Headless web testing is helping developers to increase their efficiency in work. At Vatsa Solutions, we make use of this technology in the most optimized manner to create and build projects for our clients. Staying up-to-date with the latest entrants helps us to carry out pioneering work over the latest platforms. To know more about how we can help you, feel free to connect with us at contact@vsplc.com.

[MPBOX id=3366]

Recommended Posts