Loop testcases logic (Reflection and ITestContext)
Code Below :
public class BeforeMethodParametersExample {
private Method method;
private ITestContext context;
private static final Object[][] DATA1 = { new Object[] { "first" },new Object[] { "second" }, };
private int i;
@DataProvider
public Object[][] data1() {
i=i+1;
System.out.println("data provider "+1); //executes 1st
return DATA1;//first , second
}
//Method java.lang.reflect.Method; ITestContext //executes 2nd
private Method method;
private ITestContext context;
private static final Object[][] DATA1 = { new Object[] { "first" },new Object[] { "second" }, };
private int i;
@DataProvider
public Object[][] data1() {
i=i+1;
System.out.println("data provider "+1); //executes 1st
return DATA1;//first , second
}
//Method java.lang.reflect.Method; ITestContext //executes 2nd
@BeforeMethod
public void before(Method m, ITestContext ctx) {
method = m;
context = ctx;
i=i+1;
System.out.println("Name of test is " + method.getName()+" "+i); // execute 1st
}
@BeforeMethod // -3rd
public void beforeWithData(Object[] data) {
for (Object o : data) {
i=i+1;
System.out.println("Data " + o+" "+i);// execute 2nd
}
}
@Test(dataProvider="data1") //4th
public void someTest(String data) {
i=i+1;
System.out.println("Name of test is " + method.getName()+" "+i);
System.out.println("Suite name is " + context.getSuite().getName()+" "+i);
}
}
public void before(Method m, ITestContext ctx) {
method = m;
context = ctx;
i=i+1;
System.out.println("Name of test is " + method.getName()+" "+i); // execute 1st
}
@BeforeMethod // -3rd
public void beforeWithData(Object[] data) {
for (Object o : data) {
i=i+1;
System.out.println("Data " + o+" "+i);// execute 2nd
}
}
@Test(dataProvider="data1") //4th
public void someTest(String data) {
i=i+1;
System.out.println("Name of test is " + method.getName()+" "+i);
System.out.println("Suite name is " + context.getSuite().getName()+" "+i);
}
}
No comments:
Post a Comment