首页 > 解决方案 > 如何在 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

标签: javaseleniumselenium-webdriverjunitcucumber

解决方案


您可以使用以下代码在 @before 挂钩中打印场景名称。

@Before
public void scenarioInit(Scenario scenario){
    String scenarioName = scenario.getName()
   //log the name to logger or to console here
}

您可以将名称记录到记录器或控制台中。


推荐阅读