簡體   English   中英

如何在“魅力”報告中獲取黃瓜步驟和附件?

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

我能夠在基於java-cucumber-Junit的項目中生成魅力報告。 但是,我無法在執行部分中獲取黃瓜步驟。 此外,附件未附加到報告中。 我能夠根據“魅力”站點上給出的步驟生成“魅力”報告。 但是,我無法在報告的執行部分中看到步驟(鑒於當時,請給出)。 此外,報告中也不會生成附件。

跑步者類片段

    @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語句中沒有給出,並且沒有附件。

首先,您已經將迷人的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"}
        )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM