Running Selenium Tests with Chrome Headless

June 7th 2017
Author profile picture

@eliasnogueiraElias Nogueira


Before Google Chrome 59 the headless execution must be done by 3party headless browsers like PhantomJS, SlimerJS, TrifleJS, Nightmare, and HTMLUnit.

The "problem" is that these headless browsers emulate some engines, but not V8 (Chrome engine).

PhantomJS | QtWebKit
SlimerJS | Gecko (Firefox)
TrifleJS | Trident (Internet Explorer)
Nightmare | Electron

When we talk about testing, and most of the users in various segments use Google Chrome, it's necessary to simulate the real engine.

How to do it with Java

As Google Chrome shipping headless in version 59 (as you can see here) we can tell to ChromeDriver the options before the execution.

In the code below I added two options through ChromeOptions: headless and the window-size.

The headless option will tell Google Chrome to execute in headless mode.

The window-size is a way to control the responsiveness (may your site be displayed as a mobile site if you not set a window size).

You can see another way to inform the ChromeOptions here



The Noonification banner

Subscribe to get your daily round-up of top tech stories!