Headless testing in Selenium refers to running automated tests on web applications without needing a visible graphical user interface (GUI). Normally, when using Selenium, the web browser opens and displays the actions performed during the test execution. However, in headless testing, the browser operates in a background or “headless” mode, without a visible window, while still executing the test scripts.
Let’s dive in
- Advantages & disadvantages of using headless mode
- How does headless mode work?
- How to run Chrome in headless mode
- Sequitur
Advantages & disadvantages of using headless mode
Believe it or not, there are some advantages to running tests in this way and, of course, disadvantages as well.

Here are the main advantages.
- Your tests will consume fewer resources from the system they run on, mainly because there won’t be a need to open a browser. It will be more noticeable when you run tests in parallel and use many concurrent threads.
- You may notice a slight improvement in test execution time due to not needing to open a browser.
The main disadvantage is below.
- Tests will become more challenging to debug. You can’t see what happens when a test runs, making it more difficult during debugging.
How does headless mode work?

You may be wondering how WebDriver will be able to find elements and click on them when no browser window opens.
What happens is that any website visited is rendered in memory, and this is how WebDriver can locate elements.
Another thing to note is that you can still take a screenshot of a web page or element when running in headless mode!
Follow our blog
Be the first to know when we publish new content.
How to run Chrome in headless mode
We start by creating an instance of ChromeOptions as follows:
ChromeOptions options = new ChromeOptions();
Next, we can specify that we want to run our tests in headless mode in one of two ways:
- By using the setHeadless() method:
options.setHeadless(true);
- By using the addArguments() method:
options.addArguments("--headless");
Here is the code snippet which instantiates WebDriver using ChromeOptions:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
WebDriver driver = new ChromeDriver(options);
Check out our video on this topic:
Sequitur
Running tests in headless mode offers several advantages, such as faster test execution, reduced resource consumption, and the ability to run tests on servers or in continuous integration and deployment pipelines without requiring a physical display. Headless testing is particularly useful for running tests more efficiently and scalable, especially when the application’s visual aspects are not the tests’ primary focus.
Follow our blog
Be the first to know when we publish new content.