0
package PractiseTestNg;

import java.util.Hashtable;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DataproviderTest {
    @Test(dataProvider = "getData")
    public void datavalues(Hashtable<String, String> table)
    {
        System.out.print(table.get("Username"));        
    }

    @DataProvider
    public Object[][] getData()
    {
        Object[][] data=new Object[2][2];
        Hashtable<String, String> table=new Hashtable<String, String>();
        table.put("Username", "Arghya");
        data[0][0]= table;
        return data;    
    }
}

Error I am getting is as follows:

[RemoteTestNG] detected TestNG version 7.2.0 [TestNGContentHandler] [WARN] It is strongly recommended to add "> " at the top of your file, otherwise TestNG may fail or not work as expected. FAILED: datavalues org.testng.internal.reflect.MethodMatcherException: [public void PractiseTestNg.DataproviderTest.datavalues(java.util.Hashtable)] 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: datavalues([Parameter{index=0, type=java.util.Hashtable, declaredAnnotations=[]}]) Arguments: [(java.util.Hashtable) {Username=Arghya},null]

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77

1 Answers1

0

You have to add a name to your data provider explicitly, and you can wrap your Hashmap with array this way:

    @DataProvider(name = "getData")
    public Object[][] getData() {
        Hashtable<String, String> table=new Hashtable<>();
        table.put("Username", "Arghya");
        return new Object[][] {{table}};
    }

Hope this helps.

Yevhen Danchenko
  • 1,039
  • 2
  • 9
  • 17
  • Thank you @Yevhen Danchenko for your feedback on this, is this the only way to assign? – Arghya Mukherjee May 19 '20 at 05:07
  • @ArghyaMukherjee, no, but the easiest one. You can convert hashmap to an array of objects iteratively, see https://stackoverflow.com/questions/2265266/convert-hash-map-to-2d-array for details – Yevhen Danchenko May 19 '20 at 05:25