nparikh February 2016

Selenium Webdriver - passing bulk data with excel sheet by header name- more than 50 fields of form

I am looking for some solution where i want to pass 100s of records to the form where i am having more than 50 fields. I did some research for the testNG data providers but it looks like that it returns only strings so i feel that it will not be feasible to go with data providers as if its not good to pass 50 string arguments to specific function. Also i did some research to read excel file and i get two ways that either i can go with the jxl or Apache poi but with that also i am not able to read the data by the column header as if i can not go with the row and column number of approach as i have so many fields that i need to work with. The reason behind that is that in future is one field has added to single form that its going to be rework and again its not feasible.

enter image description here

I have been following this link:

for reading data column wise but any how i am not getting the records based on the column header. Do we have any other way to achieve this.



niharika_neo February 2016

  1. "testNG data providers but it looks like that it returns only strings" - incorrect. It allows you to return a multidimensional array of type Object. What kind of object you create is your own code. You may choose to read from the excel, encapsulate all the fields in one object (your own pojo) or multiple objects and then the method argument can have just those object types declared and not the 50 strings.

  2. Both jxl and poi are libraries to interact with excel. If you want to have specific interaction with excel, like reading based on header, then you need to write code for that - it doesn't come out of the box. If you are concerned about addition of one more column , then build your indices first by reading the header column, then put it in a relevant data structure and then go about reading your data.

nparikh February 2016

I finally achieved that with the help of apache poi. I created on centralized function that is returning the hashmap having title as an index. Here is that function:

Here is my main test function:

  public void createNewCustomer(List<Map<String, String>> sheetList){   

                //Step 2. Login

                for(Map<String, String> map : sheetList){
                    //Step 3. New Customer
                        //Process with excel data
            catch(InterruptedException e)
                System.out.println ("Login Exception Raised: <br> The exception get caught" + e);


//My data provider 
@DataProvider(name = "dpCreateNewCust")  
    public  Object[][] dpCreateNewCust(){
       XLSfilename = System.getProperty("user.dir")+"//src//watts//XLSFiles//testcust.xlsx";
      List<Map<String, String>> arrayObject = UtilityMethods.getXLSData(XLSfilename,Sheetname));
        return new Object[][] { {arrayObject } };

//----GetXLSData Method in UtilityMethods Class :
 public static List<Map<String, String>> getXLSData(String filename, String sheetname)
        List<String> titleList = new ArrayList<String>();
    List<Map<String, String>> sheetList = new ArrayList<Map<String, String>>();
        try {     
            FileInputStream file = new FileInputStream(filename);

            //Get the workbook instance for XLS file 
            XSSFWorkbook XLSbook = new XSSFWorkbook(file);

            //Get first sheet from the workbook
            //HSSFSheet sheet = workbook.getSheetAt(0);

Post Status

Asked in February 2016
Viewed 3,358 times
Voted 7
Answered 2 times


Leave an answer