Creating a data-driven test using TestNG
TestNG is another widely used testing framework with Selenium WebDriver. It is very similar to JUnit. TestNG has rich features for testing, such as parameterization, parallel test execution, and so on.
TestNG provides the DataProvider
feature to create data-driven tests. In this recipe, we will use the DataProvider
feature to create a simple test. Creating data-driven tests in TestNG is fairly easy when compared with JUnit.
Getting ready
The following are the steps we need to begin with:
Add TestNG dependency to the Maven
pom.xml
file:<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.4</version>
<scope>test</scope>
</dependency>
Identify the set of values that we need to test.
How to do it...
Let's create a new test and parameterize a TestNG test using the following steps:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver...