Parameterizing Tests using suite parameters
In Chapter 1, Introducing WebDriver and WebElements, we created a search test that performs a simple search on the application under test. This test searches for a given product and validates the title. We used a hardcoded value, phones
, for the search, as shown in the following code snippet:
@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'"); }
Instead of using hardcoded values, we can parameterize these values and provide them to the test method using the suite-parameter feature of TestNG. This will help to remove using hardcoded values in the test method and move them into...