Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I am trying the code in selenium and I’m getting the error. Kindly help me with the issue

import org.testng.annotations.DataProvider; import org.testng.annotations.Test;

public class testngexcel { public static ExcelReader excel = null; @Test(dataProvider = "newdata") public void testData(String username, String password, Integer age) { System.out.println(username + " - " + password + " - " + age); } @DataProvider(name = "newdata") public static Object[][] getData() { if (excel == null) { excel = new ExcelReader("C:\\Users\\Anjali.Nautiyal\\Desktop\\selenium\\testngdata.xlsx"); } String sheetName = "login"; int rows = excel.getRowCount(sheetName); int cols = excel.getColumnCount(sheetName); Object[][] data = new Object[rows - 1][cols]; for (int rowNum = 2; rowNum <= rows; rowNum++) { for (int colNum = 0; colNum < cols; colNum++) { data[rowNum - 2][colNum] = excel.getCellData(sheetName, colNum, rowNum); } } return data;


FAILED: testData org.testng.internal.reflect.MethodMatcherException: Data provider mismatch Method: testData([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.Integer, declaredAnnotations=[]}]) Arguments: [(java.lang.String)anjali,(java.lang.String)pa,(java.lang.String)25.0] at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments( at org.testng.internal.Invoker.injectParameters( at org.testng.internal.Invoker.invokeTestMethods( at org.testng.internal.TestMethodWorker.invokeTestMethods( at at org.testng.TestRunner.privateRun( at at org.testng.SuiteRunner.runTest( at org.testng.SuiteRunner.runSequentially( at org.testng.SuiteRunner.privateRun( at at org.testng.SuiteRunnerWorker.runSuite( at at org.testng.TestNG.runSuitesSequentially( at org.testng.TestNG.runSuitesLocally( at org.testng.TestNG.runSuites( at at at org.testng.remote.RemoteTestNG.initAndRun( at org.testng.remote.RemoteTestNG.main(

1 Answer

0 votes
by (50.2k points)
edited by

As you are reading from excel, all the values may be in String, unless you are converting that to an Integer

In your test, argument age to be used as an Integer.

Changing type to String should resolve the issue


dataProvider = "newdata")

 public void testData(String username, String password, String age) { System.out.println(username + " - " + password + " - " + age); }

The following code would raise the same error.

@DataProvider(name = "newdata")

 public static Object[][] getData() { return new Object[][]{ {"20"}, {"30"} }; } 

@Test(dataProvider = "newdata")

 public void testData(Integer age) { System.out.println(age); }

For more information, check out this selenium tutorial.

This Intellipaat's automation testing course will give you an introduction to software testing.

Browse Categories