美文网首页
cucumber集成extentreports测试报告

cucumber集成extentreports测试报告

作者: zychen143 | 来源:发表于2017-07-12 15:47 被阅读0次

首先看一张效果图

cucumber测试报告

接下来就是使用步骤

  1. 先在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>
  1. 进入你的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>

相关文章

网友评论

      本文标题:cucumber集成extentreports测试报告

      本文链接:https://www.haomeiwen.com/subject/guybhxtx.html