分享

cucumber集成extentreports测试报告

 huowufenghuang 2018-08-22

首先看一张效果图

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>



作者:zychen143
链接:https://www.jianshu.com/p/ea73860c7084
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多