java - 如何在 Java 中的测试结果中查看我的场景名称
问题描述
在测试结果部分,类名显示为 classMethod。我使用黄瓜测试库进行测试。在测试结果部分,我想查看我在功能文件中指定的“场景:”名称。我该怎么办?你能帮助我吗?
build.gradle 文件:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.+'
testCompile("io.github.bonigarcia:webdrivermanager:3.+")
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.+'
compile group: 'info.cukes', name: 'cucumber-java', version: '1.+'
testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testCompile group: 'org.testng', name: 'testng', version: '6.14.3'
}
RunFeature 类:
package feature;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/java/testCases" )
public class RunFeatures {
}
黄瓜特点:
Feature: OpenBrowser
Scenario: SelectBrowser
When I have opened "https://www.trendyol.com/" with "explorer" browser
解决方案
您可以使用以下代码在 @before 挂钩中打印场景名称。
@Before
public void scenarioInit(Scenario scenario){
String scenarioName = scenario.getName()
//log the name to logger or to console here
}
您可以将名称记录到记录器或控制台中。
推荐阅读
- javascript - 反应 - 图像
- twig - Shopware 6:是否可以(atm)通过插件覆盖或更好地扩展现有元素(树枝文件)?
- python-3.x - 模块“cv2.cv2”没有属性“motempl”
- spring-boot - Kotlin如何将每一行保存到类对象中?
- c++ - 使用 WinInet.h 下载给我错误
- c - 我可以使用缓冲区的输入运行程序吗?
- mysql - MYSQL - 一起使用更新和分组
- javascript - 如何防止在 React 中重新渲染整个组件?
- scikit-learn - 是否有适合初学者的简单代码,我可以在其中试验 scikit 中高斯过程示例中使用的差异内核来学习了解它们的功能?
- python - Python方程求解器(能量平衡)不起作用