How to run Selenium test cases in Headless Chrome browser

0 votes
May 17, 2019 in Selenium by Afreen
3,285 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,120 points
1,243 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,120 points
1,020 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 27, 2018 in Selenium by nsv999
• 5,500 points
6,196 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 14, 2020 in Selenium by Gitika
• 65,870 points
90,872 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,500 points
8,141 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,190 points
7,240 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
4,982 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 3, 2020 in Selenium by Sri
• 3,190 points
6,197 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,120 points
2,159 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP