I'm able to write the test results back into Excel when I execute using multi-threaded execution. But at times, some rows are getting overwritten. This is cause the Excel report not showing few test results.
Below is the @afterMethod that I used to write the results to excel sheet after every method is executed.
Please let me know how we can avoid results getting overwritten on same row while doing parallel execution.
public void excelreport() throws IOException, InterruptedException {
FileInputStream fis = new FileInputStream(outfilelocation);
XSSFWorkbook wb = new XSSFWorkbook(fis);
sheet = wb.getSheet(WorksheetName);
lastRowNum = sheet.getLastRowNum();
int i = lastRowNum + 1; // first row is column header, so starting from row 2
XSSFRow row = sheet.createRow(i);
XSSFCell testcase = row.createCell(0);
XSSFCell results = row.createCell(1);
testcase.setCellValue("Test case name");
results.setCellValue("Pass/fail");
try {
FileOutputStream out = new FileOutputStream(new File(outfilelocation));
wb.write(out);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}