How to run Selenium test cases in Headless Chrome browser?

0 votes
May 17 in Selenium by Afreen
271 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 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 in Selenium by Abha
• 27,180 points
342 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 in Selenium by Abha
• 27,180 points
32 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,110 points
1,345 views
0 votes
5 answers
0 votes
1 answer

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,110 points
1,163 views
0 votes
1 answer
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,150 points
1,255 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,150 points
1,010 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 in Selenium by Abha
• 27,180 points
205 views