i have a problem with TestNg, I am using java with Selenium. I have a message from TestNG:
testNG:org.testng.internal.reflect.MethodMatcherException: [public void utils.ExcelDataProvider.test1(java.lang.Object[][],org.testng.ITestContext) throws java.lang.InterruptedException] has no parameters defined but was found to be using a data provider (either explicitly specified or inherited from class level annotation). Data provider mismatch Method: test1([Parameter{index=0, type=[[Ljava.lang.Object;, declaredAnnotations=[]}, Parameter{index=1, type=org.testng.ITestContext, declaredAnnotations=[]}])
This is my @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);
}
this is my DataProvider
@DataProvider(name = "test1data")
public Object[][] getData() {
Object data[][]=testData(path, 0);
return data;
}
the method:
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;
}
If I write
public void test1(Object[] data,ITestContext context) throws InterruptedException {
it works (Object[]) but i need a 2-dimensional array.
Do you know what's wrong?
I'm trying to read the excel and I'd like the first column to be the KEY column and the other columns to be the data per each execution.
Thank you
