无法在ExtentReport中添加两个类的结果 [英] could not add the result of two class in the ExtentReport

查看:107
本文介绍了无法在ExtentReport中添加两个类的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

when i run first class the result is added to the report but when i run the second class the report don't keep the result of the first class

//SimpleReportFactory {

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

//头等舱Test001

//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

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

推荐答案

因为您正在使用

private ExtentReports reporter =  SimpleReportFactory.getReporter();

两次;

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

For Extent report, if u use the ExtentReport instance twice, than the details of first instace is cleared, it shows only the last, in ur case it shows you only the second instance result.

因此,尝试只启动一次范围报告,然后在整个测试周期中使用该实例.

So, try to initiate Extent Report only one time and than use this instance to the whole test cycle.

制作

ExtentReports reporter

实例全局和静态,然后使用

instance Global and static and than use this

reporter instance to the whole test cycle.

在测试执行的最后一次关闭报告程序实例.

close the reporter instance at the last of test execution.

这篇关于无法在ExtentReport中添加两个类的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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