Many a times we feel the need to run our UI automation tests in headless mode ( No browser visible) .
Few advantages are:
- Faster execution, as it does not use system resource(memory and gpu) to launch browser .
- When we do not need to bother about browser view and do not want any distraction while running tests. (Working in local machine)
Code:
ChromeOptions options= new ChromeOptions();
//Based on your screen resolution
options.addArguments(“window-size=1400,800”);
options.addArguments("--headless");
options.addArguments("--disable-gpu");
WebDriver driver = new ChromeDriver(options);
driver.get("https://testapplicationurl.com");
You can also take screenshots in headless mode.