@Afreen to run selenium test cases in a headless Chrome browser, you can use this piece of code:
package chromeHeadless;
public class HeadlessTesting {
public static void main(String[] args) throws IOException{
System.setProperty("webdriver.chrome.driver",
"ChromeDriverPath");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1200x600");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.facebook.com/");
driver.get("https://www.google.co.in/");
System.out.println("title is: " + driver.getTitle());
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("pathTOSaveFile"));
driver.quit();
}
}
Now if you run this code, it will print the title of the page and will take the screenshot as well.