错误-数据提供程序必须返回对象[][]或迭代器&;书信电报;对象&;燃气轮机;[],而不是类[[Ljava.lang.Object;
尝试从excel工作表读取数据时出错。我的环境是-POI3.10JAR,Java1.8,window错误-数据提供程序必须返回对象[][]或迭代器&;书信电报;对象&;燃气轮机;[],而不是类[[Ljava.lang.Object;,java,selenium,webdriver,testng,Java,Selenium,Webdriver,Testng,尝试从excel工作表读取数据时出错。我的环境是-POI3.10JAR,Java1.8,window [Error] org.testng.TestNGException: Data Provider public static java.lang.Object[][] mytestpackage.DataProvi.CustomerCreation() throws java.lang.Exception must return either Object[][] or Iterator&a
[Error] org.testng.TestNGException:
Data Provider public static java.lang.Object[][] mytestpackage.DataProvi.CustomerCreation() throws java.lang.Exception must return either Object[][] or Iterator<Object>[], not class [[Ljava.lang.Object;
at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:133)
这是我的数据提供者代码
@DataProvider
public static Object[][] CustomerCreation() throws Exception{
Object[][] testObjArray = ExcelUtils.getTableArray("E://TT//src//utility//TestData.xlsx","Sheet1");
return (testObjArray);
}
数据提供程序实现的代码:
@Test(dataProvider="CustomerCreation")
public void Registration_data(String Sr, String ssn) throws Exception{
请让我知道我哪里出错了
Excel实用程序代码:-
package utility;
import java.io.Closeable;
import java.io.FileInputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelUtils {
private static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell Cell;
private static XSSFRow Row;
public static Object[][] getTableArray(String FilePath, String SheetName) throws Exception {
String[][] tabArray = null;
try {
FileInputStream ExcelFile = new FileInputStream(FilePath);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
Iterator<Row> iterator = ExcelWSheet.iterator();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_STRING) {
System.out.print(cell.getStringCellValue());
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
System.out.print(cell.getBooleanCellValue());
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
System.out.print(cell.getNumericCellValue());
}
System.out.print(" - ");
}
System.out.println();
}
// ExcelWBook.close();
ExcelFile.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tabArray;
}
}
请共享
ExcelUtils
类代码。感谢回复Naveen,刚刚添加了Excel实用程序代码。请检查代码。请同时添加TestData.xlsx
文件。我尝试了上述代码。但是,由于以下原因导致出现了另一个错误::org.apache.poi.openxml4j.exceptions.InvalidFormatException:包应该包含一个内容键入part[M1.13]
您使用哪种TestNG版本?您可以尝试使用最新版本(6.10)吗?我使用的是poi的3.10版本。我确实遇到了类似的问题openxml4j.jar丢失。请添加此jar
808088336 FIRSTNAME D 8336LASTNAME 10053 Climbing Tree St Conroe 77396 111 111 111 1234 361 361 1184 9890123456 FIRSTNAME.8336LASTNAME@CONNS.COM