ExtentReports:运行使用maven-assembly-plugin创建的可执行jar文件时,HtmlReporter无法启动 [英] ExtentReports: HtmlReporter not starting when running an executable jar file created using maven-assembly-plugin

查看:139
本文介绍了ExtentReports:运行使用maven-assembly-plugin创建的可执行jar文件时,HtmlReporter无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用TestNG以编程方式执行我的测试用例.虚拟套件文件执行正常.但是,没有生成范围报告.

I am trying to execute my test cases programmatically using TestNG. The virtual suite file is executing fine. But, the Extent Report is not being generated.

获取以下异常堆栈跟踪:

Getting the following exception stacktrace:

java.lang.IllegalStateException: No reporters were started. Atleast 1 reporter must be started to create tests.
        at com.aventstack.extentreports.Report.createTest(Report.java:69)
        at com.aventstack.extentreports.ExtentReports.createTest(ExtentReports.java:241)
        at com.aventstack.extentreports.ExtentReports.createTest(ExtentReports.java:254)
        at com.automation.service.impl.ExtentReportService.setParentExtentTest(ExtentReportService.java:56)
        at com.automation.service.impl.ExtentReportService.startTest(ExtentReportService.java:64)
        at com.automation.tests.BaseTest.beforeMethod(BaseTest.java:160)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
        at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:520)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

现在,我将报告设置为在以下位置生成:

Right now, I have set my report to generate at the following location:

E:/selenium/reports/extent-reports/

然后我将屏幕快照通过字符串"./"保存在我的根文件夹中,该字符串基本上是将屏幕快照存储在E:中.

And I am saving my screenshots in my root folder by the string: "./" which basically is storing the screenshots in E:.

另一个观察结果:

  1. 我从命令行运行了mvn clean install -DskipTests=true.

之后,我切换到目标文件夹并运行以下命令:java -jar jar-file-name.jar

After that I switched to the target folder and ran the following command: java -jar jar-file-name.jar

似乎每个测试用例都由于抛出的IllegalStateException而失败.

Looks like every test cases is failing because of the IllegalStateException it is throwing.

但是屏幕截图是在target文件夹中捕获的,从技术上讲,该文件夹应存储在root fodler中.

But the screenshots were being captured in the target folder, which technically should be stored in the root fodler.

我试图更改报告和屏幕截图的位置.还让我分享一下我的ExtentReportService类的代码片段:

I tried to change locations of the report and the screenshots. Also let me share the code snipped of my ExtentReportService class:

private static void initializeExtentReport(Configuration config) {
        if (extent == null) {
            extent = new ExtentReports();
            htmlReporter = new ExtentHtmlReporter(getReportName(config));
            ClassLoader classLoader = ExtentReportService.class.getClassLoader();
            File extentConfigFile = new File(classLoader.getResource("extent-config.xml").getFile());
            htmlReporter.loadXMLConfig(extentConfigFile);
            extent.attachReporter(htmlReporter);
            extent.setSystemInfo("Environment", config.getAutomationServer());
        }
    }

预先感谢您的努力.

推荐答案

此问题已由我遇到的另一个问题解决.

This issue got fixed with the other issue I was having.

所以,我遇到的主要问题是加载extent-config.xml文件.因此,我更改了加载extent-config.xml文件的位置,如下所示:

So, the main problem I was having was loading the extent-config.xml file. Thus, I changed the location for loading the extent-config.xml file as follows:

File extentConfigFile = new File(classLoader.getResource("extent-config.xml").getFile());

File extentConfigFile = new File("./classes/extent-config.xml");

通过这种方式,测试用例将顺利执行.

In this manner, the test cases will execute smoothly.

这篇关于ExtentReports:运行使用maven-assembly-plugin创建的可执行jar文件时,HtmlReporter无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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