- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 134字
- 2021-08-13 16:08:14
Using Headless Mode
Similar to Firefox, we can run tests in headless mode with ChromeDriver. This makes Chrome tests run faster and tests run more efficiently, especially in the CI (Continuous Integration) environment.
We can run Selenium tests in headless mode by configuring the ChromeOptions class as shown in the following code snippet:
@BeforeMethod
public void setup() {
System.setProperty("webdriver.chrome.driver",
"./src/test/resources/drivers/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
driver = new ChromeDriver(chromeOptions);
driver.get("http://demo-store.seleniumacademy.com/");
}
In the preceding code, we first created an instance of the ChromeOptions class, called the setHeadless() method, that passes the value as true to launch the Chrome browser in headless mode. During the execution, you will not see the Chrome window on the screen but the test will be executed in headless mode.
推薦閱讀
- Web安全防護指南:基礎篇
- CorelDRAW X6 中文版圖形設計實戰從入門到精通
- Modern JavaScript Web Development Cookbook
- Hands-On Chatbots and Conversational UI Development
- 2018網信發展報告
- 計算機網絡工程實用教程(第2版)
- 物聯網通信技術
- CCNP TSHOOT(642-832)認證考試指南
- 從實踐中學習手機抓包與數據分析
- 精通SEO:100%網站流量提升密碼
- Guide to NoSQL with Azure Cosmos DB
- 智慧城市中的物聯網技術
- 智能物聯網:區塊鏈與霧計算融合應用詳解
- 通信系統實戰筆記:無處不在的信號處理
- 智慧的物聯網:感知中國和世界的技術