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

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.

主站蜘蛛池模板: 通辽市| 西和县| 海安县| 博湖县| 红桥区| 嘉黎县| 锡林浩特市| 鄂托克前旗| 长武县| 讷河市| 衡东县| 通州市| 廉江市| 阿拉善左旗| 黎城县| 呼伦贝尔市| 阿拉善盟| 大姚县| 古田县| 涪陵区| 滕州市| 乐清市| 海丰县| 綦江县| 涿州市| 富顺县| 嘉义县| 海淀区| 台中市| 高邮市| 左云县| 团风县| 玉田县| 同仁县| 东乡县| 闻喜县| 香河县| 久治县| 五常市| 克什克腾旗| 玉林市|