如何让 Cucumber Extent Reports 与 Cucumber 5.6.0 一起使用?

How do I get Cucumber Extent Reports to work with Cucumber 5.6.0?

我从 Cucumber 1.2.5 升级到 Cucumber 5.6.0。升级进行得相当顺利,但是我的 Extent Reports 坏了。我试图升级它们并使用 Cucumber 4 Adapter. The documentation was sparse, and I could not get it to work. So I went and downloaded the Example Implementation。我能够编译并 运行 它并获得报告。我将示例项目升级到 Cucumber 4.8.1,将 Extent Reporter 升级到 4,并且 运行,但没有创建报告。我不知所措,我的 google 搜索没有找到任何信息。

这是原始示例项目:https://github.com/foursyth/extentreports-cucumberN-example

这是我更新它的尝试:https://github.com/dougnoel/extentreports-cucumberN-example/tree/update_to_Cucumber4-adapter

这是pom.xml:

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.version>4.8.1</cucumber.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.0.12</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

这是测试运行ner:

package cucumber.examples.java.calculator;

import org.junit.runner.RunWith;

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:", "json:target/cucumber-report.json"}
, tags = { "@foo" }
)
public class RunCukesTest {

}

这是我更新到 Cucumber 5.6.0 的项目,我试图在其中保持 Extent Reports 正常工作:https://github.com/dougnoel/sentinel/tree/93_update_cucumber

Grasshopper 在评论中回答了这个问题。解决方案是他提供的fantastic instructions and code

在pom.xml我添加了:

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.1.5</version>
</dependency>

<dependency>
    <groupId>tech.grasshopper</groupId>
    <artifactId>extentreports-cucumber5-adapter</artifactId>
    <version>1.1.0</version>
</dependency>

在我的测试运行程序中,我输入:

package cucumber.examples.java.calculator;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true
    , features = "src/test/java/features"
    , glue = { "stepdefinitions", "com.dougnoel.sentinel.steps" }
    , plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}

最后一步是在 src/test/resources/ 中添加配置文件 extent.properties,仅用三行:

extent.reporter.html.start=true
extent.reporter.html.out=reports/extent-cucumber-report.html
screenshot.dir=reports/

现在一切正常!