- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 210字
- 2021-08-13 16:08:13
Using GeckoDriver
In this section, we will see how to configure and use Geckodriver for Firefox in our tests. First of all, we need to download the Geckodriver executable from https://github.com/mozilla/geckodriver/releases
Download the appropriate version of Geckodriver based on the Firefox version installed on your computer as well as the operating system. Copy the executable file into the /src/test/resources/drivers folder.
We will use the Search Test we created in Chapter 1 and modify the test to use the Geckodriver. For this, we need to modify the setup() method, provide the path of the Geckodriver binary in the webdriver.gecko.driver property, and instantiate the FirefoxDriver class:
public class SearchTest {
WebDriver driver;
@BeforeMethod
public void setup() {
System.setProperty("webdriver.gecko.driver",
"./src/test/resources/drivers/geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://demo-store.seleniumacademy.com/");
}
@Test
public void searchProduct() {
// find search box and enter search string
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Phones");
WebElement searchButton =
driver.findElement(By.className("search-button"));
searchButton.click();
assertThat(driver.getTitle())
.isEqualTo("Search results for: 'Phones'");
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
Now execute the test, and you will see Geckodriver running in the console:
1532165868138 geckodriver INFO geckodriver 0.21.0
1532165868147 geckodriver INFO Listening on 127.0.0.1:36466
It will launch a new Firefox window and execute the test. The Firefox window will be closed at the end of the execution.
- 物聯網(IoT)基礎:網絡技術+協議+用例
- 網絡故障現場處理實踐(第4版)
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 世界互聯網發展報告·2019
- 光纖通信系統與網絡(修訂版)
- 網絡工程實施技術與方案大全
- 無線傳感器網絡定位技術
- TCP/IP基礎(第2版)
- bash網絡安全運維
- 物聯網M2M開發技術:基于無線CPU-Q26XX
- ReasonML Quick Start Guide
- SD-WAN 架構與技術
- 現場總線與工業以太網及其應用技術(第2版)
- Learning IoT with Particle Photon and Electron