如何获取倾城报告中的Cucumber步骤和附件?

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

我能够在基于 java-cucumber-Junit 的项目中生成魅力报告。但是,我无法在执行部分获得黄瓜步骤。此外,附件没有附加到报告中。 我能够根据 Allure 网站上给出的步骤生成 Allure 报告。但是,我无法在报告的执行部分看到步骤(Given,when then)。此外,报告中也不会生成附件。

亚军class片段

    @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 片段

     <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>

示例黄瓜场景

    @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




步骤定义

        @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(fileExtension = "json", type = "text/json", value = "RestJsonResponse")
            public String attachResponse(Response strResponse) {
                return strResponse.asString();
            }

预期:能够在报告的某处看到 Given when then 语句。此外,将报告中的附件视为 json 个文件。

实际:报告已生成,但没有给出 when then 语句,也没有附件。

首先,您将 allure JUnit 插件与 cucumber one 搞混了。所以你需要从 surefire 配置中移除 Allure JUnit listener 并将其从 dependencies 中移除。

下一个问题是在 class 配置中覆盖 allure cucumber 插件。您应该在 pom 或 class 中配置黄瓜插件,因为 class 配置会覆盖 pom 配置。修复它的最简单方法 - 从 pom 中删除 --plugin 并将其添加到 class 配置到其他配置,如下所示:

@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"}
        )