To run WebDriver tests in headless mode using ChromeDriver, you will need to add the relevant dependencies in your pom.xml file:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
</dependency>
Now, we instruct the WebDriver to launch ChromeDriver in headless mode:
package com.sdetworld.tutorials.selenium
import io.githib.bonigarcia.wdm.ChromeDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
public class WebDriverBase{
static protected WebDriver driver;
public static void setup(){
ChromeDriverManager.geInstance.setup();
ChromeOptions chromeoptions = new ChromeOptions();
chromeoptions.addArguments(“--headless”);
driver = new ChromeDriver(chromeOptions);
}
public static void main(String[] args){
WebDriverBase.setup();
driver.get(“https://www.intellipaat.com/”);
}
}