Selenium Java - Writing the hashmap values to excel -


i trying use hashmap values writing testcase status in excel file, not writing data excel. here code -

    public void readdata() throws exception {     string filepath = system.getproperty("user.dir") + "\\test data";     string filename = "editsubscriptions.xls";     string sheetname = "datapool";      file file = new file(filepath + "\\" + filename);     fileinputstream fis = new fileinputstream(file);     workbook workbook = null;      string fileextname = filename.substring(filename.indexof("."));      if (fileextname.equals(".xlsx")) {         workbook = new xssfworkbook(fis);     } else if (fileextname.equals(".xls")) {         workbook = new hssfworkbook(fis);     }     sheet sheet = workbook.getsheet(sheetname);     int rowcount = sheet.getlastrownum() - sheet.getfirstrownum();     hashmap<string, string> hm = new hashmap<string, string>();     (int = 1; < rowcount + 1; i++) {         row row = sheet.getrow(i);         (int j = 1; j < row.getlastcellnum(); j++) {             system.out.println(row.getcell(j).getstringcellvalue());             driver.findelement(by.linktext("login")).click();             webdriverwait wait = new webdriverwait(driver, 10);             wait.until(expectedconditions.visibilityofelementlocated(by.id("username")));             driver.findelement(by.id("username")).sendkeys(row.getcell(0).tostring());             driver.findelement(by.id("password")).sendkeys(row.getcell(1).tostring());             driver.findelement(by.name("submit")).click();             thread.sleep(10000);             try {                 driver.findelement(by.linktext("logout")).click();                 webdriverwait wait1 = new webdriverwait(driver, 10);                 wait1.until(expectedconditions.visibilityofelementlocated(by.linktext("login")));                 hm.put(row.getcell(0).tostring(), "pass");             } catch (exception ex) {                 hm.put(row.getcell(0).tostring(), "fail");                 driver.get("http://www.openclinica.com");             }         }     }     set<string> keys = hm.keyset();     (string key: keys){         system.out.println("value of "+key+" is: "+hm.get(key));          string filepath1 = system.getproperty("user.dir") + "\\test data";         string filename1 = "editsubscriptions1.xls";         string sheetname1 = "datapool";          file file1 = new file(filepath1 + "\\" + filename1);         fileinputstream fis1 = new fileinputstream(file1);         workbook workbook1 = null;          string fileextname1 = filename1.substring(filename1.indexof("."));          if (fileextname1.equals(".xlsx")) {             workbook1 = new xssfworkbook(fis1);         } else if (fileextname1.equals(".xls")) {             workbook1 = new hssfworkbook(fis1);         }          sheet sheet1 = workbook1.getsheet(sheetname1);         int rowcount1 = sheet1.getlastrownum() - sheet1.getfirstrownum();          (int i=1; < rowcount1; i++){             cell cell = sheet1.getrow(i).createcell(2);             cell.setcelltype(cell.cell_type_string);             cell.setcellvalue(hm.put(key, hm.get(key)));         }     } } 

i add status pass or fail excel sheet using hashmap key. able print status in console, not transforming excel sheet.

value of hemasai is: fail value of moulikanimmala is: pass value of keshav is: fail

please me in resolving problem..

thank in advance.

int rowcount1 = sheet1.getlastrownum() - sheet1.getfirstrownum();      (int i=1; < rowcount1; i++){         cell cell = sheet1.getrow(i).createcell(2);         cell.setcelltype(cell.cell_type_string);         cell.setcellvalue(hm.put(key, hm.get(key)));     } 

your loop should start @ index 0 according doc.

it looks never loop, start @ index 1 rowcount initial 0 if start empty sheet.

edit: after comments, go solution (untested!)

 set<string> keys = hm.keyset(); string filepath1 = system.getproperty("user.dir") + "\\test data";     string filename1 = "editsubscriptions1.xls";     string sheetname1 = "datapool";      file file1 = new file(filepath1 + "\\" + filename1);     fileinputstream fis1 = new fileinputstream(file1);     workbook workbook1 = null;      string fileextname1 = filename1.substring(filename1.indexof("."));      if (fileextname1.equals(".xlsx")) {         workbook1 = new xssfworkbook(fis1);     } else if (fileextname1.equals(".xls")) {         workbook1 = new hssfworkbook(fis1);     }      sheet sheet1 = workbook1.getsheet(sheetname1);     int rowcount1 = sheet1.getlastrownum() - sheet1.getfirstrownum(); //set rownumber last set 1 (string key: keys){ //for every key write name in column 1 , result in column 2     rowcount1++; //start @ next free row      cell cell1 = sheet1.createrow(rowcount1).createcell(1);         cell cell2 = sheet1.getrow(rowcount1).createcell(2);         cell1.setcelltype(cell.cell_type_string);         cell2.setcelltype(cell.cell_type_string);         cell1.setcellvalue(key));         cell2.setcellvalue(hm.get(key)));     } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -