Selenium 如何使用之前在黄瓜
如何使用“before”创建驱动程序实例并在cucumber功能文件中启动FirefoxSelenium 如何使用之前在黄瓜,selenium,cucumber,Selenium,Cucumber,如何使用“before”创建驱动程序实例并在cucumber功能文件中启动Firefox 我熟悉背景,但以前从未使用过。此示例取自 让我们做一些简单的小黄瓜钩子的例子来理解这个概念 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
我熟悉背景,但以前从未使用过。此示例取自 让我们做一些简单的小黄瓜钩子的例子来理解这个概念
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
步骤定义
****注***:步骤定义中没有使用逻辑。只需打印步骤摘要日志*
现在图片中出现了钩子,在您的场景中,您需要在这里初始化驱动程序
挂钩
确保包导入语句应为import cucumber.api.java.After;&导入cucumber.api.java.Before;
人们经常会弄错并导入Junit注释,所以要小心这一点
输出
除了挂钩之外,您还可以使用Cucumber中其他有用的注释,请参考ToolsQA.com上的教程。这是一个非常广泛的问题,我想在当前的形式下,除了提供Cucumber的@Before上的文档链接外,这是一个无法回答的问题。您是否尝试过可以发布的代码?你想用哪种语言?
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");
}
}