Java 如何获取诱惑报告中的黄瓜步骤和附件?
我能够在基于JavaJunit的项目中生成诱惑报告。但是,我无法获取执行部分中的cumber步骤。此外,附件未附加到报告。 我能够根据诱惑网站上给出的步骤生成诱惑报告。但是,我无法看到报告执行部分中的步骤(当时给出)。此外,报告中也不会生成附件 运行程序类代码段Java 如何获取诱惑报告中的黄瓜步骤和附件?,java,cucumber,cucumber-jvm,allure,cucumber-junit,Java,Cucumber,Cucumber Jvm,Allure,Cucumber Junit,我能够在基于JavaJunit的项目中生成诱惑报告。但是,我无法获取执行部分中的cumber步骤。此外,附件未附加到报告。 我能够根据诱惑网站上给出的步骤生成诱惑报告。但是,我无法看到报告执行部分中的步骤(当时给出)。此外,报告中也不会生成附件 运行程序类代码段 @RunWith(Cucumber.class) @CucumberOptions(features = { "src/test/java/features" }, plugin = { "pretty", "
@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>
步骤定义
@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-then语句。此外,还可以将报告中的附件作为json文件查看
Actual:报告生成,但没有给出when-then语句,也没有附件。首先,你把allure JUnit插件和cucumber one搞混了。所以你需要从surefire配置中删除allure JUnit listener,并将其从依赖项中删除 下一个问题是在类配置中覆盖诱惑cucumber插件。您应该在pom或类中配置cucumber插件,因为类配置覆盖pom配置。修复它的最简单方法是从pom中删除--插件,并将其添加到类配置中,如下所示:
@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"}
)
谢谢你的回答。我使用junit插件只是为了点击和试用。我删除了它。你的解决方案是正确的。POM配置被覆盖。当cucumber选项和POM更新时,它会起作用。另外,执行此操作时的另一个更改是使用allure serve target\allure results而不是surefire-reports启动reporting server。还有,是否有其他更改我们需要为@attachments做的其他考虑事项?我上面的@Attachment代码并没有附加json响应。我是在从步骤定义调用的方法中调用它的。但是,Allure.addAttachment(“RestJsonResponse_direct”,“text/json”,strResponse.asString(),“json”)可以工作。
@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"}
)