I am using TestNG @DataProvider
Annotation along with @Factory
functionality in order to run a flow. When the control goes to @DataProvider
method, I want to know from which test class this dataprovider method was called & on basis of that I want to supply test data.
This is my Bean class:
public class Bean {
private String fName = null;
private String lName = null;
private String address = null;
public synchronized String getfName() {
return fName;
}
public synchronized void setfName(String fName) {
this.fName = fName;
}
public synchronized String getlName() {
return lName;
}
public synchronized void setlName(String lName) {
this.lName = lName;
}
public synchronized String getAddress() {
return address;
}
public synchronized void setAddress(String address) {
this.address = address;
}
}
This is my constructor of TestClass with @Factory
@Factory(dataProvider = "dataProvider")
public TestClass(Bean bean) {
this.fName = bean.getfName();
this.lName = bean.getlName();
this.address = bean.getAddress();
}
Here is my DataProvider:
@DataProvider(name = "dataProvider")
public static Object[][] dataProvider() {
// Here I want to get the Test Class from which this DataProvider was invoked, so // with that I will supply the test data accordingly.
Bean oneBean = new Bean();
oneBean.setfName("Nisarg");
oneBean.setlName("Dave");
oneBean.setAddress("India");
Bean secondBean = new Bean();
secondBean.setfName("ABCD");
secondBean.setlName("XYZ");
secondBean.setAddress("UK");
return new Object[][] {
new Object[] { oneBean },
new Object[] { secondBean }
};
}
Here in my DataProvider I know I can pass Method m or ITestContext
as parameters, but both of them are not giving me Test class Name from which it was called.
Can anyone please help on this?