将自定义文本记录到Cucumber JVM或范围报告

问题描述

请指导我将自定义文本记录在Cucumber JVM(Masterthought)或范​​围报告中。

我正在使用Cucumber Junit BDD Framework,并且在我的POM文件中具有以下依赖项-

<!-- Cucumber JVM Report -->
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>cucumber-reporting</artifactId>
        <version>5.1.0</version>
    </dependency>

    <!-- Extent Report -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.2.1</version>
    </dependency>

我的Runner文件如下-

@CucumberOptions(
    tags = {"@SANITY,@REGRESSION,@E2E"},features = "src/test/resources/cta-features/features/",plugin = {
            "json:target/cucumber-reports/cucumber.json","com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:","pretty"
    },glue = {
            "e2e.steps","e2e.hooks"
    })

@RunWith(Cucumber.class)
public class TestRunner {

@BeforeClass
public static void init() throws Exception {
    
}

@AfterClass
public static void generateReport() throws Exception {
    File reportOutputDirectory = new File("target");
    List<String> jsonFiles = new ArrayList<>();
    jsonFiles.add("target/cucumber-reports/cucumber.json");


    String buildNumber = "1";
    String projectName = "Project";


    Configuration configuration = new Configuration(reportOutputDirectory,projectName);
    // optional configuration - check javadoc for details
    configuration.addPresentationModes(PresentationMode.RUN_WITH_JENKINS);
    // do not make scenario failed when step has status SKIPPED
    configuration.setNotFailingStatuses(Collections.singleton(Status.SKIPPED));
    configuration.setBuildNumber(buildNumber);
    // addidtional metadata presented on main page
    configuration.addClassifications("Platform","Windows");
    configuration.addClassifications("Browser","Chrome");
    configuration.addClassifications("Branch","release/1.0");


    ReportBuilder reportBuilder = new ReportBuilder(jsonFiles,configuration);
    Reportable result = reportBuilder.generateReports();
    // and here validate 'result' to decide what to do if report has failed
}

我能够在主思想和范围内成功生成报告,其中将包含功能级别语句和步骤级别语句(为此我使用了censing.write)。但是我的客户想要更深一层,他可以在其中获取有关单击了哪个链接或按钮等的信息,目前我正在使用Log4j将其发布到控制台 例子:

Log.info(“单击了随机按钮或链接,操作成功”)

我的客户希望将其集成到报告中(无论是基于“高级思想”还是“范围”)。有办法吗?

解决方法

扩展黄瓜适配器提供addtestlog来记录其他步骤。

请检查以下示例-

ExtentCucumberAdapter.addAddTestStepLog(BTN.getText());

根据您的Pom.xml文件,如果找不到方法尝试切换到黄瓜适配器6和黄瓜6的其他基本依赖性,则您正在使用适配器4,这肯定会帮助您:)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...