Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

We are considering upgrading our production server from Ubuntu-desktop 10.04 to Ubuntu-server 12.04.

We have various services running on our current desktop OS such as Selenium Web Driver. My question is can the Selenium Web Driver be run from a CLI-based system?

My immediate thought is that it can't because it relies on Firefox, but I'd like for someone to prove me wrong!

1 Answer

0 votes
by (62.9k points)

Basically, you want to run a headless-browser. Yes, it’s possible to run Selenium headlessly. Before you can begin testing, there are a couple of things you’ll need to install first:

  • Java

  • Selenium

  • ChromeDriver (latest)

ChromeOptions is a class in Selenium to set the arguments to ChromeDriver. In the following example, we will pass the two arguments to ChromeDriver to run in headless mode.

package chrome;

       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://contentstack.built.io");

                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();

            }

        }

If you run this code, it will print the title of the page and will take the screenshot as well.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...