猿问

Selenium 中的数据提供程序不匹配错误与 TestNG 和 Java

您能否就从 Selenium Java 实现 Excel 流时出现的数据提供程序不匹配错误的可能原因提出建议。


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)


料青山看我应如是
浏览 269回答 2
2回答

繁华开满天机

org.testng.internal.reflect.MethodMatcherException:&nbsp;Data provider mismatchMethod: 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]&nbsp; &nbsp; at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:45)&nbsp; &nbsp; at org.testng.internal.Parameters.injectParameters(Parameters.java:796)&nbsp; &nbsp; at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:983)&nbsp; &nbsp; at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)&nbsp; &nbsp; at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)&nbsp; &nbsp; at org.testng.TestRunner.privateRun(TestRunner.java:648)&nbsp; &nbsp; at org.testng.TestRunner.run(TestRunner.java:505)&nbsp; &nbsp; at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)&nbsp; &nbsp; at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)&nbsp; &nbsp; at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)&nbsp; &nbsp; at org.testng.SuiteRunner.run(SuiteRunner.java:364)&nbsp; &nbsp; at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)&nbsp; &nbsp; at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)&nbsp; &nbsp; at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)&nbsp; &nbsp; at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)&nbsp; &nbsp; at org.testng.TestNG.runSuites(TestNG.java:1049)&nbsp; &nbsp; at org.testng.TestNG.run(TestNG.java:1017)&nbsp; &nbsp; at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)&nbsp; &nbsp; at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)&nbsp; &nbsp; at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)根据上述错误,该createFlow()方法期望 String 作为参数,但您传递的Cell是不可接受的。试试下面的修改代码:public static Object[][] TestData() {&nbsp; &nbsp; sheet = book.getSheetAt(0);&nbsp; &nbsp; int rowCount = sheet.getLastRowNum();&nbsp; &nbsp; int cellCount = sheet.getRow(0).getLastCellNum();&nbsp; &nbsp; Object[][] data = new Object[rowCount][cellCount];&nbsp; &nbsp; for (int i = 0; i < rowCount; i++) {&nbsp; &nbsp; &nbsp; &nbsp; for (int j = 0; j < cellCount; j++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Call 'getStringCellValue()' here instead of using just 'getCell()'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data[i][j] = sheet.getRow(1).getCell(j).getStringCellValue().trim();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return data;}您需要调用该getStringCellValue()方法来获取字符串数据。更新 :如果您尝试使用getStringCellValue().为避免此异常,您可以'在 Excel 工作表的数字单元格中附加撇号作为前缀。假设您在 excel 中有一些如下格式的数据:| Ali&nbsp; &nbsp;|| 123&nbsp; &nbsp;|| Puppy |你可以得到Ali,Puppy使用的值,getStringCellValue()但你不能得到123,因为它是数字所以尝试在 excel 中追加'并按123Enter 键。它看起来像这样,你不会得到那个错误。| Ali&nbsp; &nbsp;|| '123&nbsp; || Puppy |如果您想获取数据而不考虑从 excel 提供的数据类型并且您不想追加,'那么您需要执行以下操作:public static Object[][] TestData() {&nbsp; &nbsp; sheet = book.getSheetAt(0);&nbsp; &nbsp; int rowCount = sheet.getLastRowNum();&nbsp; &nbsp; int cellCount = sheet.getRow(0).getLastCellNum();&nbsp; &nbsp; Object[][] data = new Object[rowCount][cellCount];&nbsp; &nbsp; for (int i = 0; i < rowCount; i++) {&nbsp; &nbsp; &nbsp; &nbsp; for (int j = 0; j < cellCount; j++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (sheet.getRow(1).getCell(j).getCellType()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case Cell.CELL_TYPE_NUMERIC:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Call 'getNumericCellValue()' here instead of using just 'getCell()'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data[i][j] = sheet.getRow(1).getCell(j).getNumericCellValue();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case Cell.CELL_TYPE_STRING:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Call 'getStringCellValue()' here instead of using just 'getCell()'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data[i][j] = sheet.getRow(1).getCell(j).getStringCellValue().trim();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return data;}Cell从import org.apache.poi.ss.usermodel.Cell;包中导入。我希望它有帮助...

吃鸡游戏

@DataProvider(name = "yourDPname")public Object[][] getData() {&nbsp; &nbsp; Object[][] data = TestUtil.TestData();&nbsp; &nbsp; return data;}@Test(dataProvider = "yourDPname")public void CreateFlow(String firstName, String lastName, String address,&nbsp; &nbsp; &nbsp; &nbsp; String email, String DOB, String MobileNumber, String HomeNumber,&nbsp; &nbsp; &nbsp; &nbsp; String PIN, String id, String secondID, String AccountID, String number)&nbsp; &nbsp; &nbsp; &nbsp; throws IOException, InterruptedException {&nbsp; &nbsp; //Printing all these values inside this method }}也许尝试为您的数据提供者分配名称并替换数据提供者名称而不是方法名称。
随时随地看视频慕课网APP

相关分类

Java
我要回答