My problem here is i cant able to convert the Hashtable array into object array. here content reading reads each and every row from the xls file and saves it in the hashtable array in this format:
roleName=testRole981, admin=admin, projectName=Automateme, userPassword=aspiresys12, roleDesc=grant[testplan_execute],grant[testplan_create_build],grant[testplan_metrics], adminPass=admin, userName=mur.
I want to convert that hashTable array into an object array so that i can pass those in my testNG test cases as a DataProvider.
public class DriverScript {
//public boolean isExecuted = true;
Object[][] Obj = new Object[100][100];
@SuppressWarnings("unchecked")
@DataProvider(name="Test")
public Object[][] ValidDataProvider() {
Utilities util = new Utilities();
String pathValue = Utilities.LocatingXls("Data.xls");
Hashtable<String, String>[] hashDrv = (Hashtable<String, String>[]) util.contentReading(pathValue, "Scenario1");
Object[][] Obj = new Object[100][100];
for(int i=0;i<hashDrv.length;i++)
{
System.out.println("cont vector reading" + hashDrv[i].get("projectName"));
Obj[i][0] = hashDrv[i];
}
System.out.println("outsideloop" + Obj[0][0]);
return Obj;
}
@SuppressWarnings("unchecked")
@Test(dataProvider = "Test")
public void methodtest(Hashtable <String, String> a)
{
/* Utilities util = new Utilities();
String pathValue = Utilities.LocatingXls("Data.xls");
Hashtable<String, String>[] hashDrv = (Hashtable<String, String>[]) util.contentReading(pathValue, "Scenario1");
for(int i=0;i<hashDrv.length;i++)
{
System.out.println("cont vector reading" + hashDrv[i].get("projectName"));
Scenario1 scnTst=new Scenario1(hashDrv[i]);
scnTst.check1();
}
if(!isExecuted)
{
Assert.fail("falied");
}
}*/
}}
The
Hashtableclass implements theMapinterface. This interface has a method on it calledvalues()- that returns aCollection. You can then calltoArray()on that collection to get an array.Example:
Issues:
Hashtableis probably not the best class for you to use, tryHashMap.HashTableis synchronized, so if you're not looking to be thread safe, using that class will result in slower code.Map map = new HashMap();(orHashtableif you prefer.