About Headless Browsers and Headless Testing

Posted By Aditi Nahar | 31-Dec-2018

In this article, I will discuss Headless browsers, why to use them and when not to use them, what is Headless testing and its importance. And lastly an introduction and use of Headless Chrome tool.




Headless Browsers are web browsers which don’t have a head or GUI (Graphical User Interface). This means a program runs at the backend to access the web pages but nothing is seen on the screen.


Why use Headless browsers?

  • To run tests on headless systems like Linux operating system without GUI.
  • To run tests parallelly on multiple browsers on a single machine.
  • To utilize minimum resources as GUI is not there.
  • Need to run the test just for data creation and not for actual testing.


When not to use these browsers?

  • Where there is a need to visually observe the tests on the browser.
  • As everything is running on backend and nothing is seen on the screen and UI is not a part of testing so it does not give the exact feedback of what users will actually experience on the website.
  • Sometimes errors thrown by Headless browsers are not observed on real browsers.


Introduction to Headless testing and its importance


Headless testing is a method through which browser UI tests can be executed without the head, which implies that there is no browser GUI for running the tests. This is helpful in environments where running the tests does not require the GUI, for eg in a CI environment. With headless browsers, tests execution is fast in a real browser environment so it offers high performance.


What is Headless Chrome?


Headless Chrome is one of the tools which helps in Headless testing on Chrome browser. It can be used in the latest versions (59+) of Google Chrome. It makes it possible to interact with the websites without having a window on the screen.

To work with Headless Chrome, only a terminal and the latest version of Google Chrome is required.

chrome --headless --disable-gpu

Let’s see some example of basic operations by Headless Chrome:

1. To create PDF of a page.


chrome --headless --disable-gpu --print-to-pdf

<webpage URL>


The result to this will be a pdf file of webpage titled as output.pdf.


2. To capture a screenshot of a page.


chrome --headless --disable-gpu --screenshot

<webpage URL>


The result to this will be a screenshot of webpage titled as screenshot.png.


To take a screenshot of a custom size, --window-size flag needs to be added to the command.

chrome --headless --disable-gpu --screenshot --window-size = 1290,1690

<webpage URL>


Hope this article will help you in dealing with Headless browsers and headless testing.

Request for Proposal

Recaptcha is required.

Sending message..