How to get the Cucumber steps and attachments in Allure report?

user7645022 :

I am able to generate allure report in a java-cucumber-Junit based Project. However, I am unable to get the cucumber steps in the execution section. Also, The attachments are not getting attached to the reports. I am able to generate the Allure report based on the steps given on Allure site. However, I am unable to see the steps(Given, when then) in the execution section of the report. Also, The attachments are also not generated in the report.

Runner class snippet

    @RunWith(Cucumber.class)
    @CucumberOptions(features = { "src/test/java/features" }, 
    plugin = { "pretty", "html:target/cucumber-html-reports",
            "json:target/cucumber-html-reports/cucumber.json","rerun:target/failed_scenarios.txt" }, monochrome = true, glue = { "definitions" }, tags = {"@SmokeTest"}
            )

POM snippet

     <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <!-- <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> -->
            <aspectj.version>1.8.10</aspectj.version>
            <allureVersion>2.10.0</allureVersion>
            <cucumberversion>4.2.0</cucumberversion>

            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>

        <testFailureIgnore>false</testFailureIgnore>

                        <encoding>UTF-8</encoding>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArgument>-Werror</compilerArgument>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>

                    <configuration>
                        <forkCount>3</forkCount>
                        <reuseForks>true</reuseForks>
                        <argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar" -Dcucumber.options="--plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm" -Xmx1024m -XX:MaxPermSize=256m
                        </argLine>
                        <properties>
                        <property>
                            <name>listener</name>

        <value>io.qameta.allure.junit4.AllureJunit4</value>
                        </property>
                    </properties>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>

            </plugins>
        </build>
        <dependencies>
            <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit4</artifactId>
                <version>${allureVersion}</version>
            <scope>test</scope>
        </dependency>
            <dependency>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-cucumber4-jvm</artifactId>
                <version>${allureVersion}</version>
            </dependency>
            <!-- <dependency> <groupId>io.qameta.allure</groupId> 
        <artifactId>allure-plugin-api</artifactId> 
                <version>${allureVersion}</version> </dependency> -->
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>${cucumberversion}</version>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-core</artifactId>
                <version>${cucumberversion}</version>
            </dependency>

            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-junit</artifactId>
                <version>${cucumberversion}</version>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-picocontainer</artifactId>
                <version>${cucumberversion}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-configuration2</artifactId>
                <version>2.4</version>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>json-schema-validator</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>json-path</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>xml-path</artifactId>
                <version>3.3.0</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>

sample cucumber scenario

    @SmokeTest  

        Scenario: multiply a and b 
            Given I have variable a 
            And I have variable b 
            When I multiplication a and b 
            Then I display the Result




step def

        @Given("^I have variable a$")
        public void i_have_variable_a() throws Exception {
            System.out.println("at step : I have variable a");

        }

        @Given("^I have variable b$")
        public void i_have_variable_b() throws Exception {
            System.out.println("at step : I have variable b");

        }

        @When("^I multiplication a and b$")
        public void i_multiplication_a_and_b() throws Exception {
            System.out.println("at step : multiplication");

        }

        @Then("^I display the Result$")
        public void i_display_the_Result() throws Exception {
            System.out.println("at step : result display");

        }

Attachment code -- (not used in above example code but used in actual code


       @Attachment(fileExtension = "json", type = "text/json", value = "RestJsonResponse")
            public String attachResponse(Response strResponse) {
                return strResponse.asString();
            }

Expected: Able to see the Given when then statements somewhere in the report. Also, to see attachments in the report as json files.

Actual: Report generates but no given when then statements and no attachments.

Viktor Sidochenko :

First of all, you've messed allure JUnit plugin with cucumber one. So you need to remove Allure JUnit listener from the surefire configuration and remove it from dependencies.

Next problem is in the overriding allure cucumber plugin in the class configuration. You should configure cucumber plugin in pom or class only because class config overrides pom configuration. The simplest way to fix it - remove --plugin from pom and add it to class configuration to other configs like this:

@RunWith(Cucumber.class)
@CucumberOptions(features = { "src/test/java/features" }, 
plugin = { "pretty", "html:target/cucumber-html-reports", "io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm",
        "json:target/cucumber-html-reports/cucumber.json","rerun:target/failed_scenarios.txt" }, monochrome = true, glue = { "definitions" }, tags = {"@SmokeTest"}
        )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=167179&siteId=1