Cucumber场景大纲和具有通用步骤定义的示例
我有一个功能文件,如下所示:Cucumber场景大纲和具有通用步骤定义的示例,cucumber,cucumber-jvm,Cucumber,Cucumber Jvm,我有一个功能文件,如下所示: Scenario Outline: Create ABC Given I open the application When I enter username as <username> And I enter password as <password> Then I enter title as <title> And press submit Examples: | username |
Scenario Outline: Create ABC
Given I open the application
When I enter username as <username>
And I enter password as <password>
Then I enter title as <title>
And press submit
Examples:
| username | password | title |
| Rob | xyz1 | title1 |
| Bob | xyz1 | title2 |
我可以进去吗
@When("^I enter username as <username>$")
public void I_enter_username_as_username(<something to use the value passed>) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
“^I以$”形式输入用户名时,”
public void I\u输入\u username\u作为\u username()抛出可丢弃{
//用您希望的代码表达上面的Regexp
抛出新的PendingException();
}
您应该使用此格式
Scenario Outline: Create ABC
Given I open the application
When I enter username as "<username>"
And I enter password as "<password>"
Then I enter title as "<title>"
And press submit
arg1
现在将传递您的用户名/值。Cucumber将自动在控制台中提供缺少的步骤。只需进行一次试运行,控制台中将显示缺少的步骤
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty" }, features = { "<path_to_feature>" },
glue = { "<optional_steps_location_java_file>" }, dryRun = true,
tags = { "<optional_NOT_req_for_now>" })
public class RunMyCucumberTest {
}
@RunWith(Cucumber.class)
@CucumberOptions(插件={“漂亮”},功能={”“},
glue={“”},dryRun=true,
标记={'})
公共类RunMyCucumberTest{
}
谢谢!我还想解释一下\“([^ \“]*)\”是一个正则表达式,它查找一个以引号“开头,以未定义的其他字符数结尾的字符串(星号*提供了这一点)。因此,如果我们看“我们可以看到它以引号开头”。希望这对某人有所帮助。正如@hipokito所阐明的,当(“^I输入用户名为”(.+)\“$”)时,
”)
这是怎么发生的?它一定是一些老的cucumber插件,现在的outline得到了很好的支持,并且在出现的情况下只生成一个通用的step函数。通过JUnit执行时,无需更改为“CucumberJVM 1.2.5上仍然发生”。因此使用引号:-)
@When("^I enter username as \"([^\"]*)\"$")
public void I_enter_username_as(String arg1) throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "pretty" }, features = { "<path_to_feature>" },
glue = { "<optional_steps_location_java_file>" }, dryRun = true,
tags = { "<optional_NOT_req_for_now>" })
public class RunMyCucumberTest {
}