范围报告发布并行测试 [英] Extent Report Issue Parallel testing

查看:100
本文介绍了范围报告发布并行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下报告代码:

public class Reporting {
    private ExtentHtmlReporter extentHtmlReporter;

    private static ThreadLocal<ExtentReports> extentReports = new ThreadLocal<>();
    private static ThreadLocal<ExtentTest> extentTest = new ThreadLocal<>();

    public synchronized ExtentTest createInstanceReport(String testCaseName) {
        System.out.println(extentReports.get());

        new File(Constants.userDir + "/Reports/").mkdirs();

        // To generate report with name
        extentHtmlReporter = new ExtentHtmlReporter(
                Constants.userDir + "/Reports/" +
                        "ExecutionReport_" + new SimpleDateFormat(
                        Constants.date).format(new Date()) + ".html");

        // Setting Document Title
        extentHtmlReporter.config().setDocumentTitle("Demo");
        // Setting Report Name
        extentHtmlReporter.config().setReportName("Demo Automation");
        // Setting Theme
        extentHtmlReporter.config().setTheme(Theme.STANDARD);
        // Setting Chart location
        extentHtmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
        // Setting Chart visibility
        extentHtmlReporter.config().setChartVisibilityOnOpen(false);
        // Setting Time stamp
        extentHtmlReporter.config().setTimeStampFormat("yyyy-MM-dd HH:mm:ss");
        // Setting append exist as true
        extentHtmlReporter.setAppendExisting(true);
        ExtentReports extentReports = new ExtentReports();
        extentReports.attachReporter(extentHtmlReporter);

        // Setting system info
        extentReports.setSystemInfo("Name",
                BaseTest.prop.getProperty(Constants.testerName));
        extentReports.setSystemInfo("Environment",
                BaseTest.prop.getProperty(Constants.environment));
        extentReports.setSystemInfo("Browser",
                BaseTest.prop.getProperty(Constants.browser));
        Reporting.extentReports.set(extentReports); // Instead of using here extentReport thread like this, Can anyone suggest to use it directly

        // Add test case name in report
        ExtentTest extentTest = Reporting.extentTest.get();
        extentTest = Reporting.extentReports.get().createTest(testCaseName);
        Reporting.extentTest.set(extentTest);

        // Assigning categories
        extentTest.assignCategory(MultiFunction.getProp()
                .getProperty(Constants.browser));

        System.out.println(Reporting.extentReports.get());
        System.out.println(Reporting.extentTest.get());

        return extentTest;
    }

    public synchronized ExtentTest getExtentTest() {
        return extentTest.get();
    }

    public synchronized ExtentReports getInstanceReport() {
        return extentReports.get();
    }

    public synchronized void remove() {
        extentReports.remove();
        extentTest.remove();
    }
}

我正在尝试使用TestNG进行并行测试(将来将不得不使用Selenium网格和调味料).我 执行2个测试用例 ,然后 仅一个测试 用例结果被添加到报告中.

I was trying parallel testing using TestNG (and will have to use Selenium grid and sauce in future). I execute 2 test cases then only one test case result is added in the report.

我已经使用threadPool隔离了extentTestextentReporter WebDriver 实例.

I have isolated the extentTest, extentReporter and WebDriver instances using threadPool.

下面尝试使用extentHtmlReporter实例:

1) Tried to make it static(no luck)  
2) Tried to make it local (the same behaviour, getting only 1 test case result)
3) Tried as a non-static global variable ( no luck)

您能建议如何解决上述问题吗?

Could you suggest how to solve the above issue?

请注意:仅生成一份报告.但是,当我尝试在调试模式下运行并行测试用例时,会为两个测试用例生成报告.我认为是因为一个测试用例克服了杀死某个实例的麻烦(在非调试模式下运行)

Please note: Only one report is generated. But when I tried to run parallel test cases in debug mode reports are generated for both the test case. I think because one test case gets over its killing some instance (when running in non-debug mode)

此外,我想在代码中重新设计以下位置:

Also, I want to redesign the following place in my code:

对于extentRpeort,我正在使用:

Reporting.extentReports.set(extentReports);

Reporting.extentReports.set(extentReports);

要将extentReport实例添加到我的extentReport线程中.
我不想直接添加它,而是直接使用它,以减少代码行.

To add extentReport instance to my extentReport Thread.
Instead of adding like this I want to use it directly so as to reduce line of code.

推荐答案

问题在于扩展范围报告实例的刷新. 我正在使用ThreadLocal存储扩展报告实例,并刷新了错误的实例.

The issue was with the flushing of extent report instance. I was using ThreadLocal for storing extent report instance and was flushing the wrong instance.

这篇关于范围报告发布并行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆