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

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.

主站蜘蛛池模板: 城固县| 唐河县| 峡江县| 淳化县| 余姚市| 木兰县| 耿马| 兴化市| 卢湾区| 工布江达县| 玉田县| 讷河市| 永善县| 司法| 新建县| 澄江县| 乐昌市| 松潘县| 南漳县| 南丰县| 扬州市| 嘉定区| 隆化县| 宽甸| 湖北省| 兴城市| 定边县| 丹凤县| 白朗县| 衡东县| 左权县| 新野县| 太原市| 炉霍县| 桦川县| 温泉县| 信丰县| 大荔县| 永福县| 淮北市| 兴山县|