【问题标题】:Unable to generate the extent-report无法生成范围报告
【发布时间】:2019-05-24 20:11:42
【问题描述】:

使用插件 com.vimalselvam.cucumber.listener.ExtentCucumberFormatter(唯一对我有用的),我的报告已生成,但 intellij 的日志中有几个错误

我尝试使用未定义的场景生成报告(只是为了速度)。使用多个插件,作为插件

这些是我正在使用的依赖:

<dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
</dependency>
 <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.1.1</version>
</dependency>
<dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.0.9</version>
</dependency>
<dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports-cucumber4-adapter</artifactId>
            <version>1.0.7</version>
</dependency>

@CucumberOptions(plugin = {"com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:output/report.html")

@AfterClass
    public static void writeExtentReport() {
Reporter.loadXMLConfig(new File("path/extent-config.xml"));
}

错误:

log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.


java.lang.NoSuchMethodError: com.aventstack.extentreports.reporter.ExtentHtmlReporter.loadXMLConfig(Ljava/io/File;)V

at com.vimalselvam.cucumber.listener.Reporter.loadXMLConfig(Reporter.java:66)
at test.runner.TestRunner.writeExtentReport(TestRunner.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


java.lang.NullPointerException
    at com.vimalselvam.cucumber.listener.ExtentCucumberFormatter.result(ExtentCucumberFormatter.java:252)...

【问题讨论】:

    标签: java cucumber extentreports


    【解决方案1】:

    您在 pom.xml 中同时使用 vimal、avenstack 和适配器依赖项,这是不可取的,也是不可预期的。在特定用例中应使用 vimal 或 avenstack 或两者一起使用,或仅使用适配器依赖项。请按照以下说明进行操作。

    Vimal Selvam 库:以下是所需的 maven 依赖项和一个示例测试,用于演示如何完成配置设置。

    Maven 依赖

    <dependency>
        <groupId>com.vimalselvam</groupId>
        <artifactId>cucumber-extentsreport</artifactId>
        <version>3.1.1</version>
    </dependency>
    
    
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>4.0.9</version>
    </dependency>
    

    请注意Java 8+和添加ExtentReport v3.1.1+的依赖是必须的。

    黄瓜转轮文件

     @RunWith(Cucumber.class)
        @CucumberOptions(
                features = {"src/test/resources/features"},
                glue = {"com.cucumber.stepdefinitions"},
                plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
                )
        public class RunCukesTest {
            @AfterClass
            public static void teardown() {
                Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
                Reporter.setSystemInfo("user", System.getProperty("user.name"));
                Reporter.setSystemInfo("os", "Mac OSX");
                Reporter.setTestRunnerOutput("Sample test runner output message");
            }
        }
    

    上述设置将在输出目录中生成报告,名称为report.html。

    请从 pom.xml 中删除适配器依赖项。我们将使用 vimal/avenstack 或 extent 适配器,但不能一起使用。

    Extent Adapter: 优点在于,除了在下面的运行器中设置适配器之外,您无需在任何地方编写任何代码以这种方式生成报告。

    Maven 依赖

    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.0.6</version>
    </dependency>
    

    com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter 插件添加到运行器。

    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
    public class RunCukesTest {
        // ..
    } 
    

    报告输出目录 - ../Project Directory/test-output/HtmlReport

    附加说明:以后,我们会要求您使用 Cucumber v>=4.0.0,因为您使用的是相当旧的依赖项(v1.2.5 ) 的黄瓜。

    为此,您可以添加以下一组黄瓜最小依赖项。

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.2.6</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>4.2.6</version>
        <scope>test</scope>
    </dependency>
    

    【讨论】:

    • 我在回来之前尝试正确地做你所说的,好消息:没有错误了。我用 io.cucumber 依赖项而不是 info.cukes 更新了我的 pom.xml。 坏消息我的报告没有生成:pom 只有 cucumber4-adapter,在测试运行器中我需要在@BeforeClass 中添加以下内容:ExtentReports extentReports = new ExtentReports(); extentReports.setGherkinDialect("pt"); 因为语言是葡萄牙语.我是否需要调用一个方法将报告生成到课后或类似的东西中?
    • 现在我尝试处理 cucumber-extentsreportextentreports 依赖项,删除适配器。但也没有成功:(
    • @FelipeLuz - 您可以在哪里解决未生成范围报告的问题。我的项目面临同样的问题。请帮忙。
    • @Suraj Gupta,请分享你的 pom.xml
    • 嗨 @TheSociety 添加了 POM。请看一看。我检查了您对其他一些帖子(stackoverflow.com/questions/55763356/…)的评论,以及您建议不要同时使用 ExtentAdapter 和 ExtentReport 的地方。也试过了(因此代码被注释了)。提前致谢。
    【解决方案2】:
      <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuraton>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.21.0</version>
                    <configuration>
                        <configuration>
                        <parallel>classes</parallel>
                        <threadCount>2</threadCount>
                        </configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
                <plugin>
                        <groupId>net.masterthought</groupId>
                        <artifactId>maven-cucumber-reporting</artifactId>
                        <version>4.10.0</version>
                        <executions>
                            <execution>
                                <id>execution</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                                <configuration>
                                    <projectName>CucumberWebGui</projectName>
                                    <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
                                    <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
            </plugins>
        </build> 
        
        <licenses>
            <license>
                <name>MIT License</name>
                <url>http://www.opensource.org/licenses/mit-license.php</url>
                <distribution>repo</distribution>
            </license>
        </licenses>
      
    
      
       <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <cucumber.version>4.8.0</cucumber.version>
            <!-- <extentreports.version>5.0.3</extentreports.version> -->
        </properties>
    
      <dependencies>
        
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumber.version}</version>
                <!-- <scope>test</scope> -->
            </dependency>
            
            <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    
           
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>gherkin</artifactId>
        <version>2.12.2</version>
        <scope>provided</scope>
    </dependency>
    
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.10</version>
                <!-- <scope>test</scope> -->
            </dependency>
            
            <dependency>
                <groupId>com.beust</groupId>
                <artifactId>jcommander</artifactId>
                <version>1.72</version>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-testng</artifactId>
                <version>${cucumber.version}</version>
            </dependency>
            
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.17</version>
            </dependency>
            
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
                <version>3.17</version>
            </dependency>
            
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                 <version>6.1.0</version>
            </dependency>
            
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            
           
            <dependency>
                <groupId>com.aventstack</groupId>
                <artifactId>klov-reporter</artifactId>
                <version>5.0.0</version>
            </dependency>
            
            <dependency>
                <groupId>io.github.bonigarcia</groupId>
                <artifactId>webdrivermanager</artifactId>
                <version>3.8.0</version>
            </dependency>
    
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-server</artifactId>
                <version>3.12.0</version>
            </dependency>
            
            
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.0.11</version>
    </dependency>
    
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumber.version}</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- <dependency>
                <groupId>com.aventstack</groupId>
                <artifactId>extentreports</artifactId>
                <version>5.0.4-SNAPSHOT</version>
                <version>4.0.9</version>
                <scope>provided</scope>
            </dependency> -->
            
            
            <dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.10.0</version>
    </dependency> 
            
            <!-- <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.7</version>
            </dependency> -->
        </dependencies>
    
        <distributionManagement>
            <snapshotRepository>
                <id>ossrh</id>
                <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            </snapshotRepository>
            <repository>
                <id>ossrh</id>
                <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
            </repository>
        </distributionManagement>
    
    <profiles>
      <profile>
         <id>allow-snapshots</id>
            <activation><activeByDefault>true</activeByDefault></activation>
         <repositories>
           <repository>
             <id>snapshots-repo</id>
             <url>https://oss.sonatype.org/content/repositories/snapshots</url>
             <releases><enabled>false</enabled></releases>
             <snapshots><enabled>true</enabled></snapshots>
           </repository>
         </repositories>
       </profile>
    
            <profile>
            
                <id>release</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.sonatype.plugins</groupId>
                            <artifactId>nexus-staging-maven-plugin</artifactId>
                            <version>1.6.8</version>
                            <extensions>true</extensions>
                            <configuration>
                                <serverId>ossrh</serverId>
                                <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                                <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            </configuration>
                        </plugin>
    
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-source-plugin</artifactId>
                            <version>3.0.1</version>
                            <executions>
                                <execution>
                                    <id>attach-sources</id>
                                    <goals>
                                        <goal>jar-no-fork</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
    
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>3.0.1</version>
                            <executions>
                                <execution>
                                    <id>attach-javadocs</id>
                                    <goals>
                                        <goal>jar</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
    
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-gpg-plugin</artifactId>
                            <version>1.6</version>
                            <executions>
                                <execution>
                                    <id>sign-artifacts</id>
                                    <phase>verify</phase>
                                    <goals>
                                        <goal>sign</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
      
      <name>WebAutomation</name>
      <url>http://maven.apache.org</url>
        <description>Web Automation Framework</description>
        <organization>
            <name>MidTrans Demo</name>
        </organization>
    </project>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2016-12-23
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      相关资源
      最近更新 更多