Scenario:-
My Testdata is 1)String A 2) String B 3) String C
Now i have class in which i have data provider and factory and Data provider has 3 value as String
public class TestParent {
public String tenant;
@Factory(dataProvider = "myList")
public TestParent(String s) {
tenant = s;
}
@DataProvider(name = "myList")
public Object[][] myList() {
List<String> s = new ArrayList<String>();
s.add("A");
s.add("B");
s.add("C");
Object[][] objArray = new Object[s.size()][];
for (int i = 0; i < s.size(); i++) {
objArray[i] = new Object[1];
objArray[i][0] = s.get(i);
}
return objArray;
}
@Test()
public void setup() {
System.out.print(tenant);
System.out.print("\n");
}
@Test(dependsonMethod = setup)
public void beforeclass() {
System.out.print("Hello");
System.out.print(tenant);
System.out.print("\n");
}
@Test(dependsonMethod = beforeclass)
public void afterclass() {
System.out.print("BYE");
System.out.print(tenant);
System.out.print("\n");
}
@Test(dependsonMethod = afterclass)
public void mm() {
System.out.print("YES");
System.out.print(tenant);
System.out.print("\n");
}
}
Output i want
A
HelloA
BYEA
YESA
B
HelloB
BYEB
YESB
C
HelloC
BYEC
YESC
Create two separate classes FactoryClass and TestDataClass and then run the FactoryClass from textng.xml
FactoryClass:
TestDataClass:
XML File:
If you Face Sequence issue: Link