How to run Selenium test cases in Headless Chrome browser

0 votes
May 17, 2019 in Selenium by Afreen
2,719 views

1 answer to this question.

0 votes

@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.

answered May 17, 2019 by Kushal

Related Questions In Selenium

0 votes
2 answers

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,040 points
951 views
0 votes
1 answer

How to run test cases in headless mode using Phantom JS?

Hi Bhanu, you can run test cases ...READ MORE

answered Aug 14, 2019 in Selenium by Abha
• 28,040 points
748 views
0 votes
1 answer

Selenium ChromeDriver issue - Want to run it in background, but not as headless browser

This is a flaw with ChromeDriver. Tried ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,520 points
5,169 views
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 13, 2020 in Selenium by Gitika
• 65,870 points
67,548 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
5,089 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,824 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
3,595 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
4,335 views
0 votes
1 answer
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12, 2019 in Selenium by Abha
• 28,040 points
1,597 views