Parameterizing Tests with a Data Provider
While suite parameters are useful for simple parameterization, they are not sufficient for creating data-driven tests with multiple test data values and reading data from external files, such as property files, CSV, Excel, or databases. In this case, we can use a Data Provider
to supply the values need to test. A Data Provider
is a method defined in the test class that returns an array of array of objects. This method is annotated with the @DataProvider
annotation.
Let's modify the preceding test to use the Data Provider
. Instead of using a single searchWord, we will now use three combinations of searchWords
and expected items
counts returned by the search. We will add a new method, named provider(), in the SearchTest class, as shown in following code, before the @BeforeMethod
annotation:
public class SearchTest { WebDriver driver; @DataProvider(name = "searchWords") public Object[][] provider() { return new Object[][]{ {"phones...