Automation in Headless mode | Tech

Reading Time: 2 minutes

Hi Readers, In this blog, I am going to explore, how to run an automation script in headless mode for Gmail login.

Basically, A headless browser executes a script without UI(Graphical user Interface). It can run without a real browser means in the system, if a browser is not installed still script will be executed with the help of headless. In this case, parallel execution is possible. Equally, users can perform other tasks simultaneously and the users run the script in headless mode then which is faster than actual UI testing.

This is very useful for testing web pages because they are able to read and understand DOM elements of webpage the same way. For example- styling of elements such as page layout, color, font selection, and execution of JavaScript and Ajax which are usually not available when using other testing methods.

Why use a headless browser for test execution?

We use a headless browser for test execution because it provides benefits like-

  1. It helps in CI pipeline
  2. It helps in Web Scraping
  3. It’s faster execution
  4. Supports for multiple browser version

Arguments in Script for headless-

We need to define the different arguments- window size, headless, start maximized, etc in the script.

There are various arguments like below-

ChromeOptions option=new ChromeOptions();
option.addArguments("--window-size=1920,1080","--disable-gpu", "--disable-extensions", "--no-sandbox", "-incognito");

In the above code, in the headless mode using the addArguments() method of the ChromeOptions class provided by the Selenium WebDriver.

Selenium Support for Headless Browsers:-

In Selenium, We need to build some libraries and import some classes.

1. Go to Automation IDE- To get started, open the “Preferences” window in Eclipse. Navigate to “Java » Build Path » User Libraries” on the left-hand side and click the “New” button. Enter the library name and click the “OK” button (leave the “System Library” checkbox alone)

2. Find the locators– find the locators according to Gmail account sign-in and write the script-

Selenium WebDriver provides a class for Chrome Browser is ChromeOptions, which can specify certain configurations to change the default behavior of Chrome.


For the Firefox browser, Selenium WebDriver provides a class is FireFoxOptions.

import org.openqa.selenium.firefox.FirefoxOptions;

For the Edge browser, Selenium WebDriver Provides a class is EdgeOptions.

import org.openqa.selenium.edge.EdgeOptions;

I hope you enjoyed it and it helped you!! stay connected for more future blogs. 

Thank you!!


Scala Future

Written by 

Soniya is a QA consultant having experience of more than 3 years. She has experience with Performance testing, API testing and Automation testing(Selenium, Katalon, Cypress and k6). She is always eager to learn new and advanced concepts.