Cucumber-JVM 3 - 使用 Maven 的 Allure 2 测试报告

Cucumber-JVM 3 - Allure 2 Test Report with Maven

在最近发布的 cucumber-jvm 3.x.x 中,似乎没有可行的教程,除了较旧的 1.x.x (docs)。

我不确定使用哪一个?

预期结果:

target/target/site中使用Cucumber-JVM 3在运行mvn testmvn verify后使用Maven生成Allure2测试报告。

工作 pom.xml@CucumberOptions 受到追捧。谢谢!


更新:(2018-08-31)

pom.xml

<properties>
    <!-- Project -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <app.name>Simply Do - Balance Projector</app.name>
    <!-- Maven -->
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
    <!-- Allure Test Report -->
    <aspectj.version>1.9.1</aspectj.version>
    <!-- Core Dependencies -->
    <selenium.version>3.14.0</selenium.version>
    <ngwebdriver.version>1.1.4</ngwebdriver.version>
    <cucumber.version>3.0.2</cucumber.version>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.paulhammant/ngwebdriver -->
    <dependency>
        <groupId>com.paulhammant</groupId>
        <artifactId>ngwebdriver</artifactId>
        <version>${ngwebdriver.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.11.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.11.1</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-cucumber3-jvm -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-cucumber3-jvm</artifactId>
        <version>2.7.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.13</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.codoid.products/fillo -->
    <dependency>
        <groupId>com.codoid.products</groupId>
        <artifactId>fillo</artifactId>
        <version>1.18</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.7.1</version>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-project-info-reports-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>3.0.0</version>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <!-- Ignore src/main in JAR packaging -->
            <configuration>
                <classesDirectory>src</classesDirectory>
                <excludes>
                    <exclude>main</exclude>
                </excludes>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>**/RunCukesTest.java</include>
                </includes>
                <testFailureIgnore>true</testFailureIgnore>
                <reportsDirectory>${project.build.directory}/test-output/${timestamp}</reportsDirectory>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
            </configuration>
            <dependencies>
                <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-maven -->
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.9</version>
            <configuration>
                <reportVersion>2.7.0</reportVersion>
                <allureDownloadUrl>https://github.com/allure-framework/allure2/releases/download/2.7.0/allure-2.7.0.zip</allureDownloadUrl>
            </configuration>
        </plugin>
        <!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
        <plugin>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>3.20.0</version>
            <executions>
                <execution>
                    <id>execution</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <projectName>${app.name}</projectName>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <jsonFiles>
                            <param>**/cucumber-report.json</param>
                        </jsonFiles>
                        <classificationFiles>
                            <param>**/classifications/*.properties</param>
                        </classificationFiles>
                        <parallelTesting>false</parallelTesting>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

构建日志:

pastebin

由于 Cucumber 的重大变化 API,对于不同版本的 Cucumber JVM,您将需要不同的 Allure 适配器:

  1. Cucumber JVM 1.x 需要 allure-cucumber-jvm,格式化程序 io.qameta.allure.cucumberjvm.AllureCucumberJvm
  2. Cucumber JVM 2.x 需要 allure-cucumber2-jvm,格式化程序 io.qameta.allure.cucumber2jvm.AllureCucumber2Jvm
  3. Cucumber JVM 3.x 需要 allure-cucumber3-jvm,格式化程序 io.qameta.allure.cucumber3jvm.AllureCucumber3Jvm
  4. Cucumber JVM 4.x 需要 allure-cucumber4-jvm,格式化程序 io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm

allure-maven 插件负责报告生成,可与上述任何适配器一起使用

更新: 我在这里用 Cucumber JVM 3.x + Allure 2 + Maven 创建了示例项目: https://github.com/letsrokk/Whosebug-examples/tree/master/allure-cucumber-example

您可以 运行 测试并立即提供报告

$ mvn clean test allure:serve

或者执行测试并只构建报告而不打开它

$ mvn clean test allure:report
...
$ ls -l target/site/allure-maven-plugin/
total 4744
-rw-r--r--   1 user  CORP\Domain Users     2220 Aug 29 12:49 allure-maven.html
-rw-r--r--   1 user  CORP\Domain Users   726434 Aug 29 12:49 app.js
drwxr-xr-x  12 user  CORP\Domain Users      384 Aug 29 12:49 data
drwxr-xr-x   5 user  CORP\Domain Users      160 Aug 29 12:49 export
-rw-r--r--   1 user  CORP\Domain Users    15086 Aug 29 12:49 favicon.ico
drwxr-xr-x   7 user  CORP\Domain Users      224 Aug 29 12:49 history
-rw-r--r--   1 user  CORP\Domain Users      657 Aug 29 12:49 index.html
drwxr-xr-x   9 user  CORP\Domain Users      288 Aug 29 12:49 plugins
-rw-r--r--   1 user  CORP\Domain Users  1673197 Aug 29 12:49 styles.css
drwxr-xr-x  16 user  CORP\Domain Users      512 Aug 29 12:49 widgets