我有一个复杂的问题,请阅读 - 我想使用我的框架运行范围报告,该框架是使用 Cucumber、testng 和 java 创建的。
我正在运行 testng 文件来运行测试类文件,该文件最终将运行 @CucumberOptions 和其中添加的功能。
我的测试类使用 AbstractTestNGCucumberTests 进行了扩展,以支持使用 Cucumber 进行测试。
现在一切正常。正在生成基本测试报告。 注意:我正在并行运行一些测试,它们也运行良好。
现在我想在我的框架中实现范围报告。你能告诉我如何使用插件来做到这一点,该插件添加与功能文件中添加的 cucumber 语句相同的日志。
ps:我已经浏览了一些链接,它向我展示了如何使用@AfterClass 运行 junit 的范围报告,以及如何将其与 testng 一起使用。
我试过的 -
使用的库 - com.aventstack --> extentreports 和 com.vimalselvam --> cucumber-extentsreport
错误 - cucumber.runtime.CucumberException:无法加载插件类:com.vimalselvam.cucumber.ExtentCucumberFormatter
使用的插件 - plugin = {"com.vimalselvam.cucumber.ExtentCucumberFormatter:output/report.html"}
在@AfterTest 下添加的代码是:Reporter.loadXMLConfig(new File("xml path")
请帮忙!!! 我想生成也支持并行执行的范围报告。
最佳答案
如果你想并行运行测试用例并且想要有稳定的范围报告,请使用 cucumber 4.x.x 版本,在 Cucumber 中有两种实现范围报告的方法
1. Using Cucumber-JVM 4 adapter for Extent Framework(extentreports-cucumber4-adapter)&下面是实现的步骤-(美女-你不需要写任何代码除了在下面的运行器中设置适配器之外,任何以这种方式生成报告的地方)
在POM.XML下添加适配器依赖
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.6</version>
</dependency>
将 com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter 插件添加到运行器。
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
public class RunCukesTest {
// ..
}
报告输出目录 - ../Project Directory/test-output/HtmlReport
2。在POM.XML下添加aventstack依赖
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
在此工作流程中,不要将 com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter 插件添加到运行器。
关于testing - 范围报告插件不适用于 testng + cucumber,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55955236/