范围报告 report.endTest(test) 方法?

Extent report report.endTest(test) method?

我在摆弄 Selenium Java 范围报告。他们的新版本已于 10 月 12 日发布,但我没有看到 endTest 方法。他们还没有发布 v3.0.0 的完整文档。大部分内容在用法方面都差不多,但 endTest 方法似乎不再可用。

有谁知道如何结束一个测试运行以便可以在同一个报告文件中显示多个测试?

report = ExtentFactory.getInstance(date, time);
test = report.createTest("mytest");
test.log(Status.INFO, "test started");
// do some other stuff
report.endTest(test);  <-- this is no longer an option.

有人知道结束测试的新方法是什么吗?

我能找到的只有

report.close();

但这似乎不允许我将多个测试放入同一份报告中。

版本 3 完全不同 - 您现在可以决定需要哪些记者。下面的示例同时使用 Html 和 ExtentX:

ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("filePath");
ExtentXReporter extentxReporter = new ExtentXReporter("host");

ExtentReports extent = new ExtentReports();
extent.attachReporter(htmlReporter, extentxReporter);

不再需要结束个别测试,您只需要担心记录事件。下面将开始并向报告添加 2 个测试:

extent.createTest("Test1").pass("pass");
extent.createTest("Test2").error("error");

写入结果文件与之前相同:

extent.flush();

根据您的测试运行器(我将展示如何将其与 TestNG 一起使用),您现在必须创建测试并向其中添加信息,如下所示(以下方法支持多线程):

public class ExtentTestNGReportBuilder {

    private ThreadLocal<ExtentTest> parentTest;
    private ThreadLocal<ExtentTest> test;

    @BeforeClass
    public synchronized void beforeClass() {
        ExtentTest parent = ExtentTestManager.createTest(getClass().getName());
        parentTest.set(parent);
    }

    @BeforeMethod
    public synchronized void beforeMethod(Method method) {
        ExtentTest child = parentTest.get().createNode(method.getName());
        test.set(child);
    }

    @AfterMethod
    public synchronized void afterMethod(ITestResult result) {
        if (result.getStatus() == ITestResult.FAILURE)
            test.get().fail(result.getThrowable());
        else if (result.getStatus() == ITestResult.SKIP)
            test.get().skip(result.getThrowable());
        else
            test.get().pass("Test passed");

        ExtentManager.getExtent().flush();
    }

}

以上只是给你一个想法,你可以在这里找到整个代码库:https://github.com/anshooarora/extentreports-java/issues/652#issuecomment-254078018