如何在黄瓜中使用
答
这个例子是从ToolsQA
采取让我们做黄瓜钩的一些简单的小例子,是想了解这个概念。
Feature: Test Hooks
Scenario: This scenario is to test hooks functionality
Given this is the first step
When this is the second step
Then this is the third step
步骤定义
package stepDefinition;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class Hooks_Steps {
@Given("^this is the first step$")
public void This_Is_The_First_Step(){
System.out.println("This is the first step");
}
@When("^this is the second step$")
public void This_Is_The_Second_Step(){
System.out.println("This is the second step");
}
@Then("^this is the third step$")
public void This_Is_The_Third_Step(){
System.out.println("This is the third step");
}
}
**** ***注:没有在步骤定义中使用的逻辑。只需打印步骤摘要记录即可。*
现在挂钩出现在图片中,在您的情况下,您会想要在此初始化驱动程序。
鱼钩
package utilities;
import cucumber.api.java.After;
import cucumber.api.java.Before;
public class Hooks {
@Before
public void beforeScenario(){
System.out.println("This will run before the Scenario");
}
@After
public void afterScenario(){
System.out.println("This will run after the Scenario");
}
}
确保包import语句应该是进口cucumber.api.java.After; & import cucumber.api.java.Before; 经常有人误会并导入Junit Annotations,所以要小心这个。
Aparts的,你可以利用其它有用的注释黄瓜,请参考上ToolsQA.com here教程。
这是一个非常广泛的问题,除了提供有关Cucumber的@Before文档的链接之外,我猜这些问题在当前表单中不可回答。你有没有尝试过可以发布的代码?你想用什么语言,甚至? –