Using Headless Mode

Headless mode is a very useful way to run Firefox for automated testing with Selenium WebDriver. In headless mode, Firefox runs as normal only you don't see the UI components. This makes Firefox faster and tests run more efficiently, especially in the CI (Continuous Integration) environment.

We can run Selenium tests in headless mode by configuring the FirefoxOptions class, as shown in the following code snippet:

@BeforeMethodpublic void setup() {    System.setProperty("webdriver.gecko.driver",            "./src/test/resources/drivers/geckodriver 2");    FirefoxOptions firefoxOptions = new FirefoxOptions();    firefoxOptions.setHeadless(true);    driver = new FirefoxDriver(firefoxOptions);    driver.get("http://demo-store.seleniumacademy.com/" ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.