我想从功能文件中获取方案的文本名称,并将其存储到变量中,或者在我的步骤定义中打印它。以下是我的代码:
功能文件:
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
list.add(dataSnapshot.getValue(Some.class));
}
步骤定义:
Feature: Login
I want to use this template for my feature file
Scenario Outline: Login with correct credentials
Given the user is on the login page
我想打印Scenario Outline文本:使用正确的凭据登录。感谢您的帮助。谢谢!
答案 0 :(得分:1)
您可以添加Before Hook并在钩子内打印出如下所示的场景名称:
import cucumber.api.Scenario;
import cucumber.api.java.Before;
@Before
public void printScenarioName(Scenario scenario) {
System.out.println("Run into Before Hook: printScenarioName");
System.out.println("Print Scenario name in Before Hook: " + scenario.getName());
}
下面是Maven pom.xml的依赖
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Test tools -->
<junit.version>4.12</junit.version>
<!-- Cucumber version -->
<cucumber.version>1.2.5</cucumber.version>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
以上代码适用于我的本地代码,您可以从my github
获取它们答案 1 :(得分:0)
我从io.cucumber下载了黄瓜罐,我遇到了这个错误。我创建了一个新项目,其中来自info.cukes的jar然后point可以构建它的路径。 scenario.getName()现在按预期返回方案名称。这解决了我的问题。
您只需要在maven存储库中正确下载这些jar:
cucumber-core - info.cukes
cucumber-java - info.cukes
cucumber-junit - info.cukes
cucumber-jvm-deps - info.cukes
cucumber-reporting - net.masterthought
gherkin - info.cukes
junit - junit
mockito-all - org.mockito
cobertura - net.sourgeforge.cobertura
希望这有帮助。