Writing your first test script for the Edge browser

Let's set up the Microsoft WebDriver Server and create a test for testing the search feature on Microsoft Edge. We need to download and install Microsoft WebDriver Server on Windows 10 (https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/):

public class SearchTest {

WebDriver driver;

@BeforeMethod
public void setup() {

System.setProperty("webdriver.edge.driver",
"./src/test/resources/drivers/MicrosoftWebDriver.exe");

EdgeOptions options = new EdgeOptions();
options.setPageLoadStrategy("eager");

driver = new EdgeDriver(options)
;

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();
}
}

The Microsoft WebDriver Server is a standalone server executable that implements WebDriver's JSON-wire protocol, which works as a glue between the test script and the Microsoft Edge browser. In the preceding code, we need to specify the path of the executable using the webdriver.edge.driver property similarly to other browser configurations we saw earlier in the chapter. 

We also set the Page Load Strategy to eager, using the EdgeOptions class:

EdgeOptions options = new EdgeOptions();
options.setPageLoadStrategy("eager");

When navigating to a new page URL, Selenium WebDriver, by default, waits until the page has fully loaded before passing the control to the next command. This works well in most cases but can cause long wait times on pages that have to load a large number of third-party resources. Using the eager page-load strategy can make test execution faster. The eager page-load strategy will wait until the DOMContentLoaded event is complete, that is, the HTML content is downloaded and parsed only, but other resources, such as images, may still be loading. However, this may introduce flakiness where elements are dynamically loaded.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.186.201