首页 > 其他分享 >cucumber:使用cucumber-reporting 插件优化HTML report

cucumber:使用cucumber-reporting 插件优化HTML report

时间:2022-12-23 22:56:17浏览次数:71  
标签:插件 reporting cucumber PrettyCucumberReport new import configuration

承接上一篇:API 测试框架:cucumber+springBoot+restAssured

原始的cucumber report 比较粗糙,如图下:

 

我们可以通过cucumber-reporting 插件对报告进去优化,集成介绍如下:

1)在pom.xml里面添加cuccumber-reporting 插件

    <!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>${cucumber-reporting.version}</version>
        </dependency>

 

2)PrettyCucumberReport.java

增加一些configuration并生成新的报告

package com.example.demoForCucumber.config;
/*
 * @author Helen Lee
 * @create 2022/12/23
 * @description: refer to https://blog.csdn.net/qq_36665450/article/details/89792234
 */

import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import net.masterthought.cucumber.Reportable;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PrettyCucumberReport {
    public void generateCucumberReport(){
        File reportOutputDirectory = new File("target");
        List<String> jsonFiles = new ArrayList<>();
        jsonFiles.add("target/cucumberReportJsonFiles/cucumber-report.json");

        String buildNumber="1";
        String projectName="cucumberProject";
        boolean runWithJenkins = false;
        boolean parallelTesting = false;

        Configuration configuration = new Configuration(reportOutputDirectory,projectName);

        // optional configuration
        configuration.setParallelTesting(parallelTesting);
        configuration.setRunWithJenkins(runWithJenkins);
        configuration.setBuildNumber(buildNumber);
        // optionally add metadata on main page
        configuration.addClassifications("Platform","Mac");
        configuration.addClassifications("Component","API Test");
        configuration.addClassifications("Version","1.0.0");

        ReportBuilder reportBuilder = new ReportBuilder(jsonFiles,configuration);
        Reportable reportable = reportBuilder.generateReports();
    }
}

 

3) 在runner里面添加@AfterClass,并调用PrettyCucumberReport.generateCucumberReport,使得跑完测试后再生成报告

package com.example.demoForCucumber;

import com.example.demoForCucumber.config.PrettyCucumberReport;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;


@RunWith(Cucumber.class)
@CucumberOptions(
        tags = {"@API"},
        features = {"src/main/resources/features"},
        glue = {"com.example.demoForCucumber"},
        plugin = {
                "pretty",
                "html:target/cucumber",
                "json:target/cucumberReportJsonFiles/cucumber-report.json"
        }
)
public class DemoForCucumberApplicationTests {

    @AfterClass
    public static void generateReport(){
        PrettyCucumberReport prettyCucumberReport = new PrettyCucumberReport();
        prettyCucumberReport.generateCucumberReport();
    }

}

 

4)最后我们可以在target目录下看到生成了cucumber-html-reports文件夹

 

打开overview-features.html,新的报告如下:

 

 

另外还可以点tags, steps,failure的维度来查看

 

 

 



 

 



 

 



 

标签:插件,reporting,cucumber,PrettyCucumberReport,new,import,configuration
From: https://www.cnblogs.com/helenMemery/p/17001789.html

相关文章