【问题标题】:Log custom text to Cucumber JVM or Extent Reports将自定义文本记录到 Cucumber JVM 或范围报告
【发布时间】:2020-10-04 10:38:59
【问题描述】:

请指导我将方法内的自定义文本记录到 Cucumber JVM (Masterthought) 或范围报告中。

我正在使用 Cucumber Junit BDD 框架并在我的 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
}

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

Log.info("随机按钮或链接被点击操作成功")

我的客户希望将其集成到报告中(在 Masterthought 或 Extent 中)。有没有办法做到这一点?

【问题讨论】:

    标签: selenium cucumber cucumber-jvm extentreports


    【解决方案1】:

    Extent Cucumber 适配器提供 addtestlog 来记录额外的步骤。

    请查看以下示例 -

    ExtentCucumberAdapter.addAddTestStepLog(BTN.getText());

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

    【讨论】:

      猜你喜欢
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多