我正在使用.ftl模板使用Java生成自定义报告,我将使用list的概念,但如果我执行我的tc parallel,那些列表将发生冲突。那么如何实现并行性以使用相同的template.ftl生成报告?
主要类别在
之下public class Report {
public static final List<ModuleDetails> testresultssummary = new ArrayList<ModuleDetails>();
public static final List<TestCasesDetails> testresultsdetails = new ArrayList<TestCasesDetails>();
public static final List<TestStepsDetails> teststepsdetails = new ArrayList<TestStepsDetails>();
public static Map<String, Object> data = new HashMap<>();
static String MachineNumber = "";
public static void AddModuleDetails(String moduleName, int passCount, int failCount, int notRunCount) {
testresultssummary.add(new ModuleDetails(moduleName, Integer.toString(passCount), Integer.toString(failCount),
Integer.toString(notRunCount)));
}
public static void UpdateModuleDetails(String moduleName, int passCount, int failCount, int notRunCount) {
testresultssummary.set(testresultssummary.size() - 1, new ModuleDetails(moduleName, Integer.toString(passCount),
Integer.toString(failCount), Integer.toString(notRunCount)));
}
public static void addTestCase(String moduleName, String testCaseName, String scenario, String status,
String startTime, String endTime, String totalTime, String Exception, String testCaseID) {
testresultsdetails.add(new TestCasesDetails(moduleName, testCaseName, scenario, status, startTime, endTime,
totalTime, Exception, testCaseID));
}
public static void updateLastTestCase(String moduleName, String testCaseName, String scenario, String status,
String startTime, String endTime, String totalTime, String Exception, String testCaseID) {
testresultsdetails.set(testresultsdetails.size() - 1, new TestCasesDetails(moduleName, testCaseName, scenario,
status, startTime, endTime, totalTime, Exception, testCaseID));
}
public static void addTestSteps(String testCase, String description, String expected, int Step_Num) {
teststepsdetails.add(new TestStepsDetails(testCase, "Step " + Step_Num, description, expected, "Not Run"));
}
public static void AddResult(String testCase, String description, String expected, String Acutal, int Step_Num) {
teststepsdetails.set(teststepsdetails.size() - 1,
new TestStepsDetails(testCase, "Step " + Step_Num, description, expected, Acutal));
}
public static void TestExecutionSummary(String buildNumber, String machineNumber, String startTime, String endTime,
String totalTime, String screenShotPath) {
MachineNumber = machineNumber;
data.put("buildNumber", buildNumber);
data.put("machineNumber", machineNumber);
data.put("startTime", startTime);
data.put("endTime", endTime);
data.put("totalTimeTaken", totalTime);
data.put("screenShotPath", screenShotPath);
}
public static void writeToHTML() throws TemplateException {
Configuration cfg = new Configuration();
try {
Template template = cfg.getTemplate("FrameworkLibrary/Reporting/template.ftl");
data.put("testresultssummary", testresultssummary);
data.put("testresultsdetails", testresultsdetails);
data.put("teststepsdetails", teststepsdetails);
String currentDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
Writer file = new FileWriter(new File("FrameworkLibrary/Reporting/Report/" + MachineNumber + ".html"));
template.process(data, file);
file.flush();
file.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}