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
Download and install TestNG from http://testng.org/doc/index.html.
Set up a new project and add TestNG to the project's build path. You can set up the project in an IDE of your choice.
Identify the set of values that we need to test.
How to do it...
Let's parameterize a TestNG test with the following steps:
Create a new TestNG
test
class, as follows:import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; import org.testng...