selenium - 将自定义文本记录到 Cucumber JVM 或范围报告
问题描述
请指导我将方法内的自定义文本记录到 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 中)。有没有办法做到这一点 ?
解决方案
Extent Cucumber 适配器提供 addtestlog 来记录额外的步骤。
请检查以下示例 -
ExtentCucumberAdapter.addAddTestStepLog(BTN.getText());
根据您的 Pom.xml 文件,如果您找不到方法尝试切换到黄瓜适配器 6 和黄瓜 6 的其他基本依赖项,您正在使用适配器 4。那肯定会对您有所帮助:)
推荐阅读
- javascript - Bootstrape左侧边栏导航背景颜色不起作用
- bitcoin - 比特币中是否存在这样一种场景,在给定所有随机数的情况下,您无法解决密码难题?
- javascript - 使用 Stimulus 创建响应式侧边栏
- java - build.gradle java Forge 1.16.5“无法解析符号‘日期’”
- windows - 批处理如何避免相同的第二个 FOR 循环?
- excel - 使用 Excel (2016) 创建实时图表
- python - 数独回溯求解器错误
- cordova - 配置“编译”已过时,已替换为“实现”
- amazon-web-services - Boto3 和 DynamoDB - 如何模拟聚合
- django - 如果条件为真,Django 在 ModelForm 中创建字段