Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
142 views
by The go-to Tester (360 points)
What is the use of @DataProvider annotation of testng, when we need to use this ?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

We use @DataProvider annotation when you want to perform data driven testing.

Eg. Passing username and password from an excel file/csv file for your login script.

@DataProvider(name = "dataProvider")
public Object[][] createData1() {
 return new Object[][] {
   { "uname1", "password1" },
   { "username2", "pwd2"},
 };
}
 
@Test(dataProvider = "dataProvider")
public void login(String username, String password) {
 login.do(username,password);
}
 
In above example, login function will execute twice with each set of username and password.
 
Hope that helps!


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...