0

I am trying to return a map from dataprovider method in testng while reading excel using Apache POI framework.

The code I have written is this

@DataProvider(name="dp")
    public Object[][] getExcelData(String testcaseID)throws IOException {
        loadExcelDataFile();
        Row row=sheet.getRow(returnMatchingRowData(testcaseID));
        Row headerRow=sheet.getRow(0);
        Map<String, String> map=new HashMap<String, String>();
        for (int x=0; x<row.getLastCellNum(); x++) {
            String key=headerRow.getCell(x).getStringCellValue();
            String value=row.getCell(x).getStringCellValue();
            map.put(key, value);
        }
        return new Object[][]{{map}};
    }

    @Test(dataProvider="dp")
    public void test1(HashMap<String, String> map) throws IOException {
        Object[][] ob=getExcelData("TC_001");
        System.out.println(map.get("EmpName"));
        System.out.println(ob.length);
    }

I am getting following error

org.testng.TestNGException: 
Some DataProvider public java.lang.Object[][] com.orangehrm.meta.utils.ExcelUtils.getExcelData(java.lang.String) throws java.io.IOException parameters unresolved:  at 0 type class java.lang.String
nikhil udgirkar
  • 367
  • 1
  • 7
  • 23
  • 2
    Does this answer your question? [Possible to pass parameters to TestNG DataProvider?](https://stackoverflow.com/questions/666477/possible-to-pass-parameters-to-testng-dataprovider) – shihabudheenk Mar 07 '20 at 17:58

1 Answers1

0

Just try to return map, without Object declaration, like:

return map;
Villa_7
  • 508
  • 4
  • 14