【发布时间】:2020-06-06 17:45:33
【问题描述】:
我在使用 TestNg 时遇到问题,我正在使用带有 Selenium 的 java。 我有一条来自 TestNG 的消息:
testNG:org.testng.internal.reflect.MethodMatcherException: [公共 空白 utils.ExcelDataProvider.test1(java.lang.Object[][],org.testng.ITestContext) throws java.lang.InterruptedException] 没有定义参数但是 被发现正在使用数据提供者(明确指定或 从类级别注释继承)。数据提供者不匹配方法: test1([参数{index=0, type=[[Ljava.lang.Object;, 声明注释=[]},参数{index=1, type=org.testng.ITestContext, declaredAnnotations=[]}])
这是我的@Test
@Test(dataProvider = "test1data")
public void test1(Object[][] data,ITestContext context) throws InterruptedException {
ExcelUtils excel = new ExcelUtils(path, 0);
int rowCount=excel.getRowCount();
int colCount=excel.getColCount();
String iter = context.getCurrentXmlTest().getParameter("iterations");
Execute.execute(data,iter);
}
这是我的数据提供者
@DataProvider(name = "test1data")
public Object[][] getData() {
Object data[][]=testData(path, 0);
return data;
}
方法:
public Object[][] testData(String path, int sheetIndex) {
ExcelUtils excel = new ExcelUtils(path, sheetIndex);
int rowCount=excel.getRowCount();
int colCount=excel.getColCount();
Object data[][] = new Object[rowCount][colCount];
for(int j=0; j<colCount; j++){
for(int i=0;i<rowCount ;i++ ){
String cellData=excel.getCellData(i, j);
// System.out.println("cellData "+cellData);
data[j][i] = cellData;
}
}
return data;
}
如果我写
public void test1(Object[] data,ITestContext context) throws InterruptedException {
它可以工作 (Object[]) 但我需要一个二维数组。
你知道怎么回事吗?
我正在尝试读取 excel,我希望第一列是 KEY 列,其他列是每次执行的数据。
谢谢
【问题讨论】:
标签: java excel selenium testng