我应该吃黄瓜。我确实有带Selenium的项目框架,带数据驱动框架的测试,Maven。我正在用testng注释探索黄瓜的可行性。
我的问题是,我们如何在@test方法和cumber的步骤定义之间创建连接。例如,我们的代码是用@beforeclass、@test、@afterclass方法编写的。因此,我们如何使用步骤定义进行迁移。
功能文件:
Feature: Is it Friday yet?
Everybody wants to know when it's Friday
Scenario: Sunday isn't Friday
Given today is Sunday
When I ask whether it's Friday yet
步骤定义:
@Given("^today is Sunday$")
public void today_is_Sunday() {
// Write code here that turns the phrase above into concrete actions
System.out.println("this is demo1");
}
@When("^I ask whether it's Friday yet$")
public void i_ask_whether_is_s_Friday_yet() {
// Write code here that turns the phrase above into concrete actions
System.out.println("this is demo2");
}
类执行:
@CucumberOptions(features = "cfeature/firstDemo.feature", glue = { "mytest/Stepd" })
public class demo01 extends AbstractTestNGCucumberTests {
private TestNGCucumberRunner tcr;
@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
tcr = new TestNGCucumberRunner(this.getClass());
}
@Test(groups="cucumber", description="Runs CucumberFeature")
public void testdemo() {
System.out.println("Hello");
}
@AfterClass(alwaysRun = true)
public void afterClass() {
tcr.finish();
}
}
慰问:
Hello
[33mUndefined scenarios:[0m
[33mcfeature/firstDemo.feature:4 [0m# Sunday isn't Friday
1 Scenarios ([33m1 undefined[0m)
5 Steps ([33m5 undefined[0m)
0m0.073s
You can implement missing steps with the snippets below:
到目前为止,@test annotation正在调用。但是,如何用步骤定义替换它。请协助。