3

At this point with the recent release of cucumber-jvm 3.x.x, there does not seem to be a viable tutorial out there except for the older 1.x.x (docs).

I am unsure which one to use?

Expected Result:

To generate an Allure2 test report in target/ or target/site with Cucumber-JVM 3 using Maven after running mvn test or mvn verify.

A working pom.xml and @CucumberOptions are sought after. Thanks!


Update: (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>

Build Log:

pastebin

k_rollo
  • 5,304
  • 16
  • 63
  • 95

1 Answers1

5

due to breaking changes in Cucumber API, for different versions of Cucumber JVM you will need different Allure adapters:

  1. Cucumber JVM 1.x require allure-cucumber-jvm, formatter io.qameta.allure.cucumberjvm.AllureCucumberJvm
  2. Cucumber JVM 2.x require allure-cucumber2-jvm, formatter io.qameta.allure.cucumber2jvm.AllureCucumber2Jvm
  3. Cucumber JVM 3.x require allure-cucumber3-jvm, formatter io.qameta.allure.cucumber3jvm.AllureCucumber3Jvm
  4. Cucumber JVM 4.x require allure-cucumber4-jvm, formatter io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm

allure-maven plugins is responsible report generation and can be used together with any of adapters above

Update: I have created example project with Cucumber JVM 3.x + Allure 2 + Maven here: https://github.com/letsrokk/stackoverflow-examples/tree/master/allure-cucumber-example

You can either run tests and serve report straight away

$ mvn clean test allure:serve

Or execute tests and just build report without opening it

$ 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
Dmitry Mayer
  • 381
  • 1
  • 6
  • Hi, thanks for the info. Can you add a working `pom.xml` and `CucumberOptions` (for `cucumber3-jvm`) to serve as modern reference? Would be glad to mark as accepted answer if it works. – k_rollo Aug 28 '18 at 16:44
  • 1
    Hey, silver, sure. I have created an example project in github and added link to answer. Important things to looks at: `pom.xml`, `src/test/resources/allure.properties` and `CucumberTest` runner class – Dmitry Mayer Aug 29 '18 at 10:52
  • 1
    Allure is experiencing issues with its Bintray repository. For now, workaround is to specify alternative download link using `allureDownloadUrl` property in `configuration` block of `allure-maven` plugin. I updated sample project on GitHub with example. You can use GitHub artifacts `https://github.com/allure-framework/allure2/releases/download/2.7.0/allure-2.7.0.zip` or host `allure-2.7.0.zip` somewhere on your servers and put that link into `allure-maven` config – Dmitry Mayer Aug 30 '18 at 07:35
  • Hi Dmitry, follow up question. The report is not served when there are failing tests? I have set `testFailureIgnore` to `true`. – k_rollo Aug 30 '18 at 15:32
  • any error messages in the log? it would be very helpful if you can attach full build log somewhere – Dmitry Mayer Aug 30 '18 at 15:33
  • 1
    Problem is that Maven for some reason ignores tesFailureIgnore property and fails the build. I’m out of office now, can have a look at it tomorrow morning – Dmitry Mayer Aug 30 '18 at 16:36
  • 1
    Ok, so the problem is that `maven-cucumber-reporting` plugin fails the build if there were any failures in tests, and that happens before Allure goals are executed. You can either remove this plugins - because why would you need two reports anyway - or you need to find a way to configure this `maven-cucumber-reports` to not fail the build – Dmitry Mayer Aug 31 '18 at 07:53
  • 1
    This error occures: `Failed to execute goal net.masterthought:maven-cucumber-reporting:3.20.0:generate (execution) on project jcucumberng-framework: Error Found:: BUILD FAILED - Check Report For Details` – Dmitry Mayer Aug 31 '18 at 07:53
  • 1
    Or you can run tests execution and report generation in two separate commands like that: `mvn clean verify` and then `mvn allure:serve` – Dmitry Mayer Aug 31 '18 at 07:55
  • 1
    Maybe there's an option to avoid failing the build on test failures, I just never used that plugin myself :) – Dmitry Mayer Aug 31 '18 at 07:59
  • Yep, will look into that. Thank you, I have awarded your bounty. :) As far as this question is concerned, you have correctly answered it with a working example. Running 2 separate cmds is indeed viable. Cheers! – k_rollo Aug 31 '18 at 09:27
  • Great! Happy to help :) – Dmitry Mayer Aug 31 '18 at 09:33
  • 1
    `maven-cucumber-reporting` _can_ be used with Allure by adding `false` to the ``. Cheers! – k_rollo Sep 02 '18 at 07:55
  • Dmitry, would you be able to put a gradle version of the stackoverflow project you have put together above please? I can have a go at it and put a link to the repo here but I'm not too familiar with gradle. – Ilyas Patel Nov 22 '18 at 15:09
  • @DmitryMayer I've managed to create a gradle version of the stackoverflow sample. The only thing I have noticed is the Allure report is displaying the Scenario names twice, one with a full step run and the other is empty. Here is a link to the project which replicates the issue - https://github.com/IlyasPatel/stackoverflow-gradle-cucumber-allure . The .png image displays the duplicate scenario. – Ilyas Patel Nov 22 '18 at 17:34
  • @IlyasPatel hey, thanks for Gradle example! The duplication most likely happens because you have both Allure Cucumber and Allure JUnit adapters. You need only Cucumber adapter if you are using Cucumber – Dmitry Mayer Nov 23 '18 at 07:20
  • @DmitryMayer, Thank. When I remove the junit adapter, I receive a null pointer exception and the build fails but the report still gets generated. I have raised a bug here about it - https://github.com/allure-framework/allure-cucumberjvm/issues/56 – Ilyas Patel Nov 23 '18 at 09:49
  • I come to confirm it _is_ possible to create 1 project including all 3 major reporting plugins without conflicts: https://github.com/kathyrollo/jcucumberng-framework. As of this writing, all work together in `Cucumber 3.x.x`. – k_rollo Dec 07 '18 at 16:04
  • Facing similar issue running on Cucumber6 and allure 2.14.0 --No plugin found for prefix 'allure' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/rishikhanna/.m2/repository), central (https://repo.maven.apache.org/maven2)] --------- My sample POM file : https://github.com/rkhanna1401/cucumber_selenium_grid/blob/master/pom.xml Any suggestion is appreciated – RISHI KHANNA Jun 29 '21 at 11:05