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

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

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

最佳答案

因为您正在使用

private ExtentReports reporter =  SimpleReportFactory.getReporter();

两次;

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

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

制作

ExtentReports reporter

实例全局且静态,然后使用此

reporter instance to the whole test cycle.

在测试执行最后关闭报告器实例。

关于java - 无法在 ExtentReport 中添加两个类的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36180844/

相关文章:

java - Spring MVC 3.1.0 错误?升级 Controller 后不再自动检测

java - JAX-RS 中的 QueryParam 和 MatrixParam 有什么区别?

java - 如何使用 Selenium 检查可以从网页打开多少个窗口

selenium - 如何使用 Selenium(任何版本)下载图像?

testing - 当用户名和密码为空时单击登录按钮会抛出一条消息,如何打印显示的消息

java - 我将如何编写一个获取 <script> 标记内容的 Java 正则表达式?

Java:为什么 NumberFormatException 不扩展 ParseException?

python - 没有弹出窗口的 Webdriver

selenium - 如何使用 Selenium Java WebDriver 选择复选框?

java - 如何使用 selenium webdriver 和浏览器 HtmlunitDriver for Java 设置代理?