Reputation: 15
Scenario: I have built a testNG class which contains multiple test methods + an excel read method.I wish to put All the test methods to Iteration depending upon the no of rows in the excel sheet. Also I wish to selectively utilize the data values amongst test methods. ie all column 1 values to be used in test 1 only.. all col 2 values to be used in test 2 only.. so on..
I do not think this is possible through a single instance of DataProvider which is something I wish for.
Any help appreciated.
FYI I am pasting my Programming logic here:
My Programming Code: public class sample {
@DataProvider(name = "dp")
public static Object[][] readExcel() {
.
.
.
.
return data;
}
@Test(dataProvider = "dp")
public void test1(String a,String b) throws Exception {
System.out.println("test 1 OUTPUT IS "+ a);
}
@Test(dataProvider = "dp")
public void test2(String a,String b) throws Exception {
System.out.println("test 1 OUTPUT IS "+ b);
}
}
{Data in excel : Row 1: sam miller Row 2: peter paul
Output (presently coming): test 1 OUTPUT IS sam; test 1 OUTPUT IS peter; test 2 OUTPUT IS miller; test 2 OUTPUT IS paul;
Output (that is required): test 1 OUTPUT IS sam; test 2 OUTPUT IS miller; test 1 OUTPUT IS peter; test 2 OUTPUT IS paul; }
Upvotes: 0
Views: 1626
Reputation: 8531
Your dataprovider can take your method as input. You can probably name your column headers with TC name and only fetch values of column method name in your dataprovider, something like
Courtesy TestNG documentation : "If you declare your @DataProvider as taking a java.lang.reflect.Method as first parameter, TestNG will pass the current test method for this first parameter. This is particularly useful when several test methods use the same @DataProvider and you want it to return different values depending on which test method it is supplying data for."
Upvotes: 1