当我使用多线程执行时,我能够将测试结果写回 Excel。但有时,有些行会被覆盖。这是因为 Excel 报告没有显示很少的测试结果。
下面是@afterMethod
我用来在每个方法执行后将结果写入 excel 表的内容。
请让我知道我们如何避免在并行执行时在同一行上覆盖结果。
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();
}
}