I have one question though on the Datadriven framework. I have created a dataprovider which would return the value in key value pair where i used the hashmap. I need to use the returned values from the dataprovider in my main test and am not sure how to retrieve these key value pair in my main test. I am trying to do the same as csv data file but with excel. Pls help me how to do it .. thanks
@DataProvider(name = "dataExcel") public final ArrayList<LinkedHashMap<String,String>> getAllRows(String inputFile1,String strSheet){ ArrayList<LinkedHashMap<String,String>> tdrAL = new ArrayList<LinkedHashMap<String,String>> (); InputStream xlInputStream = null; System.out.println("File name inside the loop is " + inputFile1 ); System.out.println("sheet name inside the loop is " + strSheet ); try{ File wbook = new File(inputFile1); xlInputStream = new FileInputStream(wbook); Workbook xlWB = Workbook.getWorkbook(xlInputStream); Sheet xlSheet = xlWB.getSheet(strSheet); int rowCount = xlSheet.getRows(); System.out.println("Total Rows is " + rowCount); int colCount = xlSheet.getColumns(); System.out.println("Total col is " + colCount); for (int r = 1; r <rowCount; r++){ LinkedHashMap<String,String> strHM = new LinkedHashMap<String,String>() ; for( int i = 0; i < colCount; i++){ strHM.put(xlSheet.getCell(i, 0).getContents(), xlSheet.getCell(i, r).getContents()); } tdrAL.add(strHM); } } catch (Exception e){ e.printStackTrace(); } finally { try{ xlInputStream.close(); } catch (Exception e){ e.printStackTrace(); } } return tdrAL; } Now i wanted to use the returned value from the logindataInfo class in the main test method as below . public class MultipleLogin extends BaseSetup { @Test(dataProvider = "dataExcel",dataProviderClass = RegistrationDataInfo.class) public void loginLogoutTest(RegistrationDataInfo registrationdatainfo){ Newuser newuser= PageFactory.initElements(dr, Newuser .class); dr.get(htmlUrl); newuser.newregister(registrationdatainfo); } } } |
Free forum by Nabble | Edit this page |