Hi Devashish, you can parameterize tests with the help of DataProvider. DataProvider annotation passes test data to test script, which can be helpful with the scenario where you want to test login functionality with multiple credentials, let say 100 or so and you have to login one by one to make sure login is happening with all of these credentials. Below is the code sample showing usage of DataProvider:
public class DataProviderSample {
// getdata passes the test data to test script
@Test(dataProvider = "getData")
public void loginTest(String username, String password) {
System.out.println("UserName : " + username);
System.out.println("Password : " + password);
//Test Automation code
}
@DataProvider
public Object[][] getData() {
Object[][] data = new Object[4][2];
// 1st row
data[0][0] = "testuser1";
data[0][1] = "pass";
// 2nd row
data[1][0] = "testuser2";
data[1][1] = "pass2121";
// 3rd row
data[2][0] = "testuser3";
data[2][1] = "wswkdsj";
// 4th row
data[3][0] = "testuser4";
data[3][1] = "skaalk";
return data;
}
}