如何在“魅力”报告中获取黄瓜步骤和附件?

时间:2019-03-27 07:04:33

标签: java cucumber cucumber-jvm allure cucumber-junit

我能够在基于Java-Cucumber-Junit的项目中生成吸引力报告。但是,我无法在执行部分中获取黄瓜步骤。此外,附件未附加到报告中。      我能够根据“魅力”站点上给出的步骤生成“魅力”报告。但是,我无法在报告的执行部分中看到步骤(鉴于当时,请给出)。另外,报告中也不会生成附件。

Runner类摘要

    @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();
            }

预期:可以查看报表中某处的“ When when”语句。另外,要以json文件的形式查看报告中的附件。

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

1 个答案:

答案 0 :(得分:0)

首先,您已经将迷人的JUnit插件与一个黄瓜弄糟了。因此,您需要从surefire配置中删除Allure JUnit侦听器,并将其从依赖项中删除。

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

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