【发布时间】:2019-10-03 01:09:23
【问题描述】:
我应该在 Cucumber 上迁移。我确实有带有 Selenium 的项目框架,带有数据驱动框架的 TestNG,Maven。我正在使用 TestNG 注释探索 Cucumber 的可行性。
我的问题是,我们如何在 @Test 方法和黄瓜的 Step 定义之间建立联系。举个例子,我们的代码是用@BeforeClass、@Test、@AfterClass 方法编写的。那么我们如何使用 Step 定义进行迁移。
特色文件:
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 注解正在调用。但是,如何用步骤定义替换它。请帮忙。
【问题讨论】:
-
你只需要扩展类。其余的都和junit一样。 github.com/cucumber/cucumber-jvm/tree/master/testng.
-
@Grasshopper 我已经用 TestNG 替换了 Junit。我对步骤定义特别怀疑。
-
test 和 stepdefinition 之间没有直接迁移。您将需要创建适当的场景并将现有的测试逻辑拆分为步骤定义。
-
@Grasshopper 是的,我想我需要这样做。但是,从当前执行 Step 定义没有调用。如果您可以提供示例(在回答中),那就太好了。
-
您应该使用 java 包格式作为胶水选项值。也许像'mytest.Stepd'
标签: selenium cucumber testng cucumber-java