How to run Selenium test cases in Headless Chrome browser?

0 votes
May 17 in Selenium by Afreen
24 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
1 answer

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

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,050 points
145 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,050 points
668 views
0 votes
5 answers
+1 vote
1 answer

How to maximize chrome browser in Selenium Java?

You can use Chrome options for playing ...READ MORE

answered Dec 17, 2018 in Selenium by Nabarupa
682 views
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,050 points
131 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,130 points
519 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,130 points
118 views
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 4 days ago in Selenium by Abha
• 8,200 points
18 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.