Here’s the code sample from our tutorial on how to execute your tests in headless mode in Selenium for Java

 

package base;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BaseTests {
protected static ChromeDriver driver;
@BeforeAll
public static void setUp() {
WebDriverManager.chromedriver().setup(); //handles setup of chromedriver executable
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
driver = new ChromeDriver(options);
}
@AfterAll
public static void tearDown() {
driver.quit();
}
}
view raw BaseTests.java hosted with ❤ by GitHub

Angie Jones
Automation Architect

Ready for the next generation of testing?

Get started today Schedule a demo