无法在ExtentReport中添加两个类的结果

时间:2016-03-23 14:23:58

标签: java selenium selenium-webdriver

当我运行第一堂课时,结果会被添加到报告中,但是当我运行第二课时,报告不会保留第一堂课的结果

// SimpleReportFactory {

package Rapport;

import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;

public class SimpleReportFactory {

private static ExtentReports reporter;

public static synchronized ExtentReports getReporter() {
    if (reporter == null) {
        reporter = new ExtentReports("/Users/user/Desktop/untitled folder/SimpleReport3.html", true, DisplayOrder.NEWEST_FIRST);
    }
    return reporter;
}

public static synchronized void closeReporter() {
    reporter.flush();
    reporter.close();
}
}

// First Class Test001

package Rapport;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class Test001 {

private ExtentReports reporter =  SimpleReportFactory.getReporter();



@Test
public void simpleTest002()
{
    ExtentTest testReporter = reporter.startTest("simpleTest002", "This is a simple simpleTest002");
    testReporter.log(LogStatus.INFO, "Starting test simpleTest002");
    int a = 100;
    int b = 30;

    testReporter.log(LogStatus.INFO, "Loading the value of a to " + a);
    testReporter.log(LogStatus.PASS, "Loading the value of b to " + b);
    reporter.endTest(testReporter);

}

@AfterSuite
public void afterSuite()
{
    reporter.close();
}
}

//第二课Test002

package Rapport;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class Test002 {

private ExtentReports reporter =  SimpleReportFactory.getReporter();


@Test
public void simpleTest004()
{
    ExtentTest testReporter = reporter.startTest("simpleTest004", "This is a simple simpleTest004");
    testReporter.log(LogStatus.INFO, "Starting test simpleTest004");
    int a = 100;
    int b = 30;

    testReporter.log(LogStatus.INFO, "Loading the value of a to " + a);
    testReporter.log(LogStatus.PASS, "Loading the value of b to " + b);
    reporter.endTest(testReporter);

}

@AfterSuite
public void afterSuite()
{
    reporter.close();
}

1 个答案:

答案 0 :(得分:1)

因为您正在使用

private ExtentReports reporter =  SimpleReportFactory.getReporter();

两次;

对于范围报告,如果您使用ExtentReport实例两次,则清除第一个实例的详细信息,它仅显示最后一个,在您的情况下,它仅显示第二个实例结果。

因此,尝试仅启动Extent Report一次,而不是将此实例用于整个测试周期。

制作

ExtentReports reporter

实例全局和静态而不是使用此

reporter instance to the whole test cycle.

在最后一次测试执行时关闭记者实例。