官术网_书友最值得收藏!

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:

@BeforeMethod
public 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/");
}

In the preceding code, we first created an instance of the FirefoxOptions class, called the setHeadless() method, that passes the value as true to launch the Firefox browser in headless mode. You will see a long message indicating the browser instance has been launched in headless mode, as shown in the following console output:

1532194389309 geckodriver INFO geckodriver 0.21.0
1532194389317 geckodriver INFO Listening on 127.0.0.1:21734
1532194390907 mozrunner::runner INFO Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/var/folders/zr/rdwhsjk54k5bj7yr34rfftrh0000gn/T/rust_mozprofile.DmJCQRKVVRs6"
*** You are running in headless mode.

During the execution, you will not see the Firefox window on the screen but the test will be executed in headless mode.

主站蜘蛛池模板: 台中市| 沁水县| 龙南县| 霍山县| 阳江市| 桓仁| 曲阳县| 浦东新区| 罗定市| 富民县| 景洪市| 和静县| 桃园县| 资阳市| 台北县| 三原县| 简阳市| 江门市| 新密市| 浮梁县| 突泉县| 延安市| 西华县| 进贤县| 科尔| 凌云县| 福州市| 荃湾区| 灵石县| 巨野县| 合水县| 民权县| 张家川| 越西县| 修武县| 普定县| 子长县| 报价| 嘉兴市| 云浮市| 四会市|