masaj salonu masaj salonları
Home » Advertising » Running Selenium Tests With Chrome Headless

Running Selenium Tests With Chrome Headless


Before Google Chrome 59, headless execution had to be done by third-party headless browsers like PhantomJSSlimerJSTrifleJSNightmare, and HTMLUnit.

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

When we talk about testing, it’s necessary to simulate Google’s real engine, as both Internet users and web devs tend toward using Google Chrome.

How to Do it With Java

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

In the code below I added two options through ChromeOptionsheadless and the window-size.

// imports omitted
public class ChromeHeadlessTest {

    public void testExecution() throws IOException {
        System.setProperty("", "chromedrier_path");

        // Add options to Google Chrome. The window-size is important for responsive sites
        ChromeOptions options = new ChromeOptions();

        WebDriver driver = new ChromeDriver(options);

        // a guarantee that the test was really executed


The headless option will tell to Google Chrome to execute in headless mode. The window-size is a way to control the responsiveness (and allows your site be displayed, like a mobile site, if you have not set a window size).

You can see some other ways to inform the ChromeOptions here.

Leave a Reply

Your email address will not be published. Required fields are marked *


cover letter