Writing result in the input/output sheet | Selenium Forum
S
shankar gopalakrishnan Posted on 13/11/2019

Hi,

can you please help me how can i write the results in the spreadsheet during run time. I am currently using data driven framework. i created my own method as below but i am not able to increment the row if there are multiple rows in a test case. i am successfull only when there is only one data for a particular test case in the "Data" sheet. if i have multiple data then only one row is passed. could you please help is there a way i can use "Put" keyword in hashtable. i tried that too but its not working. only i am able to get the data from the data sheet during runtime.

 

public void Writedatainexcel(int a, int s, int d, String name) throws Exception {

// File src=new
// File("C:\\Users\\C629685\\eclipse-workspace\\extentreport\\InputOutputsheet\\webcentraldata.xlsx");
File src = new File(System.getProperty("user.dir") + "\\InputOutputsheet\\webcentraldata.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(a);
sheet1.getRow(s).createCell(d).setCellValue(name);
FileOutputStream fout = new FileOutputStream(src);
wb.write(fout);
fis.close();
// wb.close();

if (name == "SKIP") {
Total_Num_of_TC_Skipped = Total_Num_of_TC_Skipped + 1;
} else if (name == "PASS") {
Total_Num_of_TC_Passed = Total_Num_of_TC_Passed + 1;
} else if (name == "FAIL") {

Total_Num_of_TC_Failed_incl_att = Total_Num_of_TC_Failed_incl_att + 1;

}


S
shankar gopalakrishnan Replied on 14/11/2019

To be more specific :-

Approach 1 :: As mentioned in the training videos i created two dimentional array and passed the data in the dataprovider and i am successfully read the data using key,value pair. (i.e) using data.get("Expected_Result"){key} i am able to read. but if use the same approach for writing the data like data.put("Result") i could able to write the data only in hastable it is not writing in the excel sheet(input/output sheet). I want to know how can i write the data in excell using the same Hashtable approach please let me know....

Approach 2 :: I tried the below method as approach 2 . I created a new method but with this i am not able to increment the row because since i am using the TestNg annotation eveytime for second data the value is Reset and the result is overwritten in the same row.

 

public void Writedatainexcel(int a, int s, int d, String name) throws Exception {

// File src=new
// File("C:\\Users\\C629685\\eclipse-workspace\\extentreport\\InputOutputsheet\\webcentraldata.xlsx");
File src = new File(System.getProperty("user.dir") + "\\InputOutputsheet\\webcentraldata.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(a);
sheet1.getRow(s).createCell(d).setCellValue(name);
FileOutputStream fout = new FileOutputStream(src);
wb.write(fout);
fis.close();
// wb.close();

if (name == "SKIP") {
Total_Num_of_TC_Skipped = Total_Num_of_TC_Skipped + 1;
} else if (name == "PASS") {
Total_Num_of_TC_Passed = Total_Num_of_TC_Passed + 1;
} else if (name == "FAIL") {

Total_Num_of_TC_Failed_incl_att = Total_Num_of_TC_Failed_incl_att + 1;

}


A
Ashish Thakur Replied on 16/11/2019

We called you on skype and discussed this issue.

Hope it got resolved. Closing this issue