首先看一张效果图
接下来就是使用步骤
- 先在pom.xml文件中加入包引用
<!-- report-->
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
</dependency>
- 进入你的cucumber入口主类中
@RunWith(Cucumber.class)
@ContextConfiguration("classpath:cucumber.xml")
@CucumberOptions(
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/extent-report/report.html"},//1
format = {"json:target/cucumber-report.json","pretty"},//2
features = {"classpath:features"},
glue = {"com.xxx.steps"},
tags = {
"~@performance","~@skip"
}
)
public class CucumberTest{
@BeforeClass
public static void setup() {
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath("target/extent-report/myreport.html");
// extentProperties.setExtentXServerUrl("http://localhost:1337");
extentProperties.setProjectName("xxx");
}
@AfterClass
public static void tearDown() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));//1
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Windows");
Reporter.setTestRunnerOutput("Sample test runner output message");
}
}
- CucumberOptions中加入插件的属性
- 在
@BeforeClass
注解方法中,可以使用setReportPath
方法指定插件的报告生成位置
- 在
@AfterClass
注解方法中,可以使用loadXMLConfig
方法指定报告配置文件的位置
extent-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<extentreports>
<configuration>
<theme>dark</theme>
<encoding>UTF-8</encoding>
<documentTitle>Cucumber Extent Reports</documentTitle>
<reportName>Cucumber Extent Reports</reportName>
<!--<reportHeadline> - v1.0.0</reportHeadline>-->
<protocol>https</protocol>
<dateFormat>yyyy-MM-dd</dateFormat>
<timeFormat>HH:mm:ss</timeFormat>
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>