Writing your first test script for the Safari browser

This is as straight forward. The following is the test script using the Safari Driver:

public class SearchTest {    WebDriver driver;    @BeforeMethod    public void setup() {        driver = new SafariDriver();        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();    }}

In the preceding code, we created an instance ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.