Extent report report.endTest(test) method?

前提是你 提交于 2019-12-04 16:51:31

Version 3 is quite different - you now have the ability to decide which reporters you require. The below example uses both Html and ExtentX:

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

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

Individual tests no longer need to be ended, you only have to worry about logging events. The below will start and add 2 tests to the report:

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

Writing to the results file is the same as before:

extent.flush();

Depending upon your test-runner (I will show how to use it with TestNG), you now have to create tests and add information to them such as below (the below approach supports multi-threading):

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();
    }

}

The above is just to give you an idea, you can find the entire codebase here: https://github.com/anshooarora/extentreports-java/issues/652#issuecomment-254078018

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!