如何获取黄瓜java中的场景名称?

问题描述 投票:18回答:2

我想得到方案的名称,以获得有意义的日志,并在java中的运行时生成自定义报告。场景类只有getStatus()和getSourceTagNames()方法。我找不到获取方案名称的方法。

有人可以帮我解决这个问题吗?

cucumber cucumber-jvm
2个回答
24
投票

从版本1.6开始,除了getStatus()getSourceTagNames()之外,还有另一种方法getName()返回场景的描述。例如,对于以下情况:

Scenario: verify number of topics shown in the UI

scenario.getName()返回"verify number of topics shown in the UI"

我在@Before初始化场景如下:

@Before
public void before(Scenario scenario) {
    this.scenario = scenario;
}

希望这可以帮助。


0
投票
String scenarioName = scenario.getName();
String[] arrayScenarioName = scenarioName.split("--");
String scenarioName1 = arrayScenarioName[0]; 
String scenarioName2 = arrayScenarioName[1]; 
System.out.println("Scenario Name 1 for this test is -> " + scenarioName1);
System.out.println("Scenario Name 2 for this test is -> " + scenarioName2);

String scenarioId = scenario.getId();
//Takes the Scenario ID and removes the ; and splits it into 2 strings
String scenarioId4 = scenarioId;
String[] parts = scenarioId4.split(";");
String part1 = parts[0]; 
String part2 = parts[1]; 
String part11 = part1.replace('-', ' ');
String part22 = part2.replace('-', ' ');
System.out.println("Scenario ID for this test is -> part11 " + part11);
System.out.println("Scenario ID for this test is -> part22 " + part22);

一旦你设置了@Before,就试试这个来检索你的Cucumber功能和场景项目。

© www.soinside.com 2019 - 2024. All rights reserved.