java - 范围报告 4 未创建报告

标签 java extentreports selenium-extent-report extent

我正在尝试创建范围报告版本 v4.0.9,但无法执行此操作。 下面的代码是我编写的 setUp 类,它具有所有 before 方法和 aftermethos,并且同一类扩展到我正在执行测试的 Utilities 类。

这是setUp类的代码

public class AIG_SetUp {
    protected static ExtentLoggerReporter logger;
    protected static ExtentReports extent;
    protected static ExtentTest log;

     @BeforeTest(alwaysRun = true)
     public void starttest() {
            logger = new ExtentLoggerReporter(System.getProperty("user.dir"));
            extent = new ExtentReports();
            extent.attachReporter(logger);
            System.err.close(); // written to remove JAVA 9 incompatibility.. continued below
            System.setErr(System.out); // continue.. and remove the warnings
            extent.setSystemInfo("User Name" , "Sobhit");
     }

     @AfterMethod(alwaysRun = true)
     public void endReport(ITestResult result) {
          try {
               if (result.getStatus() == ITestResult.FAILURE) {
                    log.log(Status.FAIL , "Test cases Failed" + result.getName());
                    log.log(Status.FAIL , "Test cases Failed" + result.getThrowable());
               } else if (result.getStatus() == ITestResult.SKIP) {
                    log.log(Status.SKIP , "Test case skipped is" + result.getName());
               }
          } catch (Exception e) {
               e.printStackTrace();
          }
     }

     @AfterTest(alwaysRun = true)
     public void endReport() {
          extent.flush();

          }
     }

这是扩展至上述类的实用程序类。

public class UtilitiesOps extends AIG_SetUp {

     @Test(groups = {"Core-Smoke"}, description = "List all media types")
     public void Verify_List_all_media_types() {
         extent.attachReporter(logger);
         extent = new ExtentReports();
         log = extent.createTest("List all media types");
         log.assignCategory("Utilities Operations");

     } 

需要提及的几个要点 现在,在出现空指针异常之前,我没有收到错误,但现在没有错误。 代码也运行良好,但不生成范围报告。 如果我把所有东西都放在一个类中,没有之前的测试和东西,就能够创建报告。不知道为什么会出错。

非常感谢您的帮助。

最佳答案

阅读完相关内容后,我得到了答案。

基本上,我在没有静态变量的情况下进行了之前的测试,因为由于其他全局变量,它必须静态启动。

下面的代码解决了我的问题。

@BeforeTest(alwaysRun = true)
     public static void starttest() {
            logger = new ExtentLoggerReporter(System.getProperty("user.dir"));
            extent = new ExtentReports();
            extent.attachReporter(logger);
            System.err.close(); // written to remove JAVA 9 incompatibility.. continued below
            System.setErr(System.out); // continue.. and remove the warnings
            extent.setSystemInfo("User Name" , "Sobhit");
     }

关于java - 范围报告 4 未创建报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58336621/

相关文章:

java - 如何使用该字段的 id 通过 Servlet 读取 JSP 表单中输入字段的值?

java - 使用 apache POI 在现有 Excel 文件之间插入新列

java - 范围报告框架 - 如何获取范围报告日志函数中存储的值

java - 使用 ExtentReports 打印 Arraylist 时出错

java - 使用范围报告打印屏幕截图

java - 第二个监视器上的工具提示显示在监视器的边缘

java - 将播放服务更新到 8.3.0 后无法创建发布版本

java - 范围 : Add Class name to Test Success

java - 在执行功能文件之前删除范围报告html文件的方法?

c# - 如何将多个类文件的报告合并到 1 个范围报告测试中