- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 199字
- 2021-08-13 16:08:13
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.
- 計(jì)算機(jī)網(wǎng)絡(luò)與通信(第2版)
- 物聯(lián)網(wǎng)與北斗應(yīng)用
- SEO 20日
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- 網(wǎng)絡(luò)故障現(xiàn)場(chǎng)處理實(shí)踐(第4版)
- TCP/IP入門經(jīng)典(第5版)
- 無人機(jī)通信
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- IPv6網(wǎng)絡(luò)切片:使能千行百業(yè)新體驗(yàn)
- 通信十年:擁抱互聯(lián)網(wǎng)
- 物聯(lián)網(wǎng)場(chǎng)景設(shè)計(jì)與開發(fā)(初級(jí))
- 異構(gòu)蜂窩網(wǎng)絡(luò)關(guān)鍵理論與技術(shù)
- 商業(yè)的本質(zhì)和互聯(lián)網(wǎng)
- 人際網(wǎng)絡(luò)