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

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.

主站蜘蛛池模板: 资阳市| 大宁县| 微博| 若尔盖县| 五台县| 岑溪市| 志丹县| 营口市| 拜泉县| 福安市| 会东县| 承德市| 云和县| 卢氏县| 乌鲁木齐县| 渝北区| 美姑县| 陕西省| 赣州市| SHOW| 宝坻区| 襄垣县| 开原市| 青浦区| 饶阳县| 土默特右旗| 江阴市| 南木林县| 九龙县| 乐清市| 敦化市| 疏附县| 雅江县| 上虞市| 白城市| 平顶山市| 汤原县| 盘山县| 黄梅县| 尖扎县| 双峰县|