ExtentReports: HtmlReporter not starting when running an executable jar file created using maven-assembly-plugin

只愿长相守 提交于 2019-12-13 03:57:11

问题


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/

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

Another observation:

  1. I ran mvn clean install -DskipTests=true from command line.

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

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

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

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

Thanks in advance for the efforts.


回答1:


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

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

to

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

In this manner, the test cases will execute smoothly.



来源:https://stackoverflow.com/questions/53102340/extentreports-htmlreporter-not-starting-when-running-an-executable-jar-file-cre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!