我正在尝试将扩展区报告与本地线程一起使用,以便可以并行运行。 并行运行我的课程。
尝试并行执行测试,问题是我在初始化时犯了一些错误,因此之前由于空指针异常而失败。
BaseClass
public class BaseClass{
private static ThreadLocal<ExtentTest> testReport = new ThreadLocal<ExtentTest>();
public static ExtentReports extent;
@BeforeSuite
public void beforeSuite(ITestContext context) throws Exception {
//Initiate Extent Report
extent = ExtentReporter.createInstance(context, true);
}
@BeforeMethod
protected void setUpDriver(Method method, Object[] testArgs,ITestContext iTestContext) {
//Start Test of Extent Report
ExtentTest extentTest = extent.startTest((this.getClass().getSimpleName() + " :: " + method.getName()), method.getName());
testReport.set(extentTest);
testReport.get().assignCategory("", this.getClass().getSimpleName());
//use extent report
testReport.get().log(LogStatus.INFO, "Inside Base class - Before Method");
}
}
ExtentReporter:
public class ExtentReporter {
private static String reportName;
private static String reportPath;
private static File directory = new File(".");
private static String ReportRootFolder;
private static ExtentReports extent;
public ExtentReports getExtent() {
return this.extent;
}
public static ExtentReports getInstance(ITestContext context, boolean replaceExisting) {
try {
if (extent == null)
createInstance(context, replaceExisting);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return extent;
}
public static ExtentReports createInstance(ITestContext context, boolean replaceExisting) throws Exception {
try {
extent = new ExtentReports(reportPath, true);
extent.loadConfig(new File(reportPath));
extent.addSystemInfo("Environment", "QA");
} catch (Exception e) {
System.out.println(e.getMessage());
}
return extent;
}
}