TestNGclass Test2 с двумя тестовыми наборами, которые должны выполняться с одним и тем же набором данных. Поэтому я передаю один и тот же поставщик данных в оба случая, которые определены в другом классе TestNg Test1.
Работает нормально, когда я не передаю данные из Excel
public class Test1 {
static String filepath = new File("").getAbsolutePath();
@DataProvider(name = "sample")
public static Object[][] readdata(Method m) throws Exception {
String name = m.getName();
System.out.println("NAME===>" + name);
String[][] locationdata = null;
String[][] finallocation = null;
if ("runlocation".equals(name)) {
locationdata = XLSXReader.getData(filepath + "//src//test//java//com//Myname//dataset//Sample.xlsx", "Sheet1");
finallocation = new String[locationdata.length - 1][2];
for (int i = 1; i < locationdata.length; i++) {
String[] s = locationdata[i];
for (int j = 0; j < s.length; j++) {
finallocation[i - 1][j] = s[j];
// System.out.println(finallocation[i-1][j]);
}
}
return finallocation;
} else if ("slocation".equals(name)) {
String[][] secondlocationdata = XLSXReader.getData(filepath + "//src//test//java//com//Myname//dataset//Sample.xlsx", "Sheet2");
String[][] location = new String[secondlocationdata.length - 1][2];
for (int i = 1; i < secondlocationdata.length; i++) {
String[] s = secondlocationdata[i];
for (int j = 0; j < s.length; j++) {
location[i - 1][j] = s[j];
// System.out.println(finallocation[i-1][j]);
}
}
return location;
}
return finallocation;
}
}
public class Test2 {
static String filepath = new File("").getAbsolutePath();
@Test(dataProvider = "sample", dataProviderClass = Test1.class)
public void runlocation(String from, String to) {
System.out.println("From-->" + from + ", TO-->" + to);
}
@Test(dataProvider = "sample", dataProviderClass = Test1.class)
public void slocation(String from, String to) {
System.out.println("@@@@@From-->" + from + ", @@@@@@TO-->" + to);
}
}