Reputation: 57
Can you please suggest for the possible cause of the Data provider mismatch error which is coming in case of implementing Excel flow from Selenium Java.
org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: CreateFlow([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=4, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=5, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=6, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=7, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=8, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=9, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=10, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=11, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(org.apache.poi.xssf.usermodel.XSSFCell) AakashAuto,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) dummy,(org.apache.poi.xssf.usermodel.XSSFCell) gmaAIL.COM,(org.apache.poi.xssf.usermodel.XSSFCell) asdsad,(org.apache.poi.xssf.usermodel.XSSFCell) sads,(org.apache.poi.xssf.usermodel.XSSFCell) asd,(org.apache.poi.xssf.usermodel.XSSFCell) asd,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) asd]
at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:983)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Code which I am using to get the Data from Excel:
public static Object[][] TestData() {
Workbook workBook;
Sheet sheet;
File src = new File(FilePath);
workBook = WorkbookFactory.create(src);
sheet = book.getSheetAt(0);
int rowCount = sheet.getLastRowNum();
int cellCount = sheet.getRow(0).getLastCellNum();
Object[][] data = new Object[rowCount][cellCount];
for (int i = 0; i < rowCount; i++) {[![enter image description here][1]][1]
for (int j = 0; j < cellCount; j++) {
data[i][j] = sheet.getRow(1).getCell(j);
}
}
return data;
}
Method where I am calling this TestData:
@DataProvider
public Object[][] getData() {
Object[][] data = TestUtil.TestData();
return data;
}
@Test(dataProvider = "getData")
public void CreateFlow(String firstName, String lastName, String address, String email, String DOB,
String MobileNumber, String HomeNumber, String PIN, String id, String secondID, String AccountID,
String number) throws IOException, InterruptedException {
//Printing all these values inside this method
}
Upvotes: 1
Views: 4298
Reputation: 1
@DataProvider(name = "yourDPname")
public Object[][] getData() {
Object[][] data = TestUtil.TestData();
return data;
}
@Test(dataProvider = "yourDPname")
public void CreateFlow(String firstName, String lastName, String address,
String email, String DOB, String MobileNumber, String HomeNumber,
String PIN, String id, String secondID, String AccountID, String number)
throws IOException, InterruptedException {
//Printing all these values inside this method }
}
Maybe try to assign name to your data provider and replace the dataprovider name instead the method name.
Upvotes: 0
Reputation: 1689
org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: CreateFlow([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=4, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=5, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=6, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=7, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=8, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=9, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=10, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=11, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(org.apache.poi.xssf.usermodel.XSSFCell) AakashAuto,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) dummy,(org.apache.poi.xssf.usermodel.XSSFCell) gmaAIL.COM,(org.apache.poi.xssf.usermodel.XSSFCell) asdsad,(org.apache.poi.xssf.usermodel.XSSFCell) sads,(org.apache.poi.xssf.usermodel.XSSFCell) asd,(org.apache.poi.xssf.usermodel.XSSFCell) asd,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) Dummy,(org.apache.poi.xssf.usermodel.XSSFCell) asd]
at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)
at org.testng.internal.Parameters.injectParameters(Parameters.java:796)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:983)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
As per the above error, the createFlow()
method is expecting the String as an argument but you are passing the Cell
which is not acceptable.
Try the below modified code :
public static Object[][] TestData() {
sheet = book.getSheetAt(0);
int rowCount = sheet.getLastRowNum();
int cellCount = sheet.getRow(0).getLastCellNum();
Object[][] data = new Object[rowCount][cellCount];
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < cellCount; j++) {
// Call 'getStringCellValue()' here instead of using just 'getCell()'
data[i][j] = sheet.getRow(1).getCell(j).getStringCellValue().trim();
}
}
return data;
}
You need to call the getStringCellValue()
method to get the String data.
Update :
You will get an exception, if you are trying to read Numeric data from the excel by using getStringCellValue()
.
To avoid this exception, you can append '
apostrophe symbol as prefix in the Numeric cell of the excel sheet.
Suppose you have some data like below format in the excel :
| Ali |
| 123 |
| Puppy |
you can get Ali
, Puppy
values using getStringCellValue()
but you can't get 123
because it is Number so try to append '
before that 123
in the excel and press enter. It looks something like this and you won't get that error.
| Ali |
| '123 |
| Puppy |
If you want to fetch the data irrespective of the data type that has provided from the excel and you don't want to append '
then you need to do something like below :
public static Object[][] TestData() {
sheet = book.getSheetAt(0);
int rowCount = sheet.getLastRowNum();
int cellCount = sheet.getRow(0).getLastCellNum();
Object[][] data = new Object[rowCount][cellCount];
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < cellCount; j++) {
switch (sheet.getRow(1).getCell(j).getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
// Call 'getNumericCellValue()' here instead of using just 'getCell()'
data[i][j] = sheet.getRow(1).getCell(j).getNumericCellValue();
break;
case Cell.CELL_TYPE_STRING:
// Call 'getStringCellValue()' here instead of using just 'getCell()'
data[i][j] = sheet.getRow(1).getCell(j).getStringCellValue().trim();
break;
}
}
}
return data;
}
Import Cell
from import org.apache.poi.ss.usermodel.Cell;
package.
I hope it helps...
Upvotes: 1