黄瓜方案大纲和通用步骤定义的示例 [英] Cucumber scenario outline and examples with generic step definitions
本文介绍了黄瓜方案大纲和通用步骤定义的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Feature文件,如下所示:
场景概述:创建ABC
给定我打开应用程序
当我输入用户名为< username>
我输入密码为< password>
然后我输入标题为< title>
并按提交
示例:
|用户名|密码|标题|
| Rob | xyz1 | title1 |
| Bob | xyz1 | title2 |
这要求我对每个值都有步骤定义。我可以改为
通用步骤定义,可以映射
中的每个用户名或密码或标题值示例部分。
即不是说
@When (^我输入用户名作为Rob $)
public void I_enter_username_as_Rob()throws Throwable {
//使用你想要的代码表达正则表达式
throw new PendingException
}
可以输入
@When(^我输入用户名为< username> $)
public void I_enter_username_as_username(<使用传递的值>)throws Throwable {
//用你想要的代码表达上面的Regexp
throw new PendingException();
}
解决方案
/ p>
<$ c $ p> 场景概述:创建ABC
给定我打开的应用程序
当我输入username < username>
我输入密码为< password>
然后我输入标题为< title>
并按提交
这将产生
@When(^ I username as \([^ \] *)\$)
public void I_enter_username_as )throws Throwable {
//用你希望的代码表达Regexp
throw new PendingException();
}
arg1
现在将传递您的用户名/值。
I have a Feature file which is as below:
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 |
This mandates me to have step definitions for each of these values. Can i instead have a
generic step definition that can be mapped for every username or password or title values in
the examples section.
i.e instead of saying
@When("^I enter username as Rob$")
public void I_enter_username_as_Rob() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
can i enter
@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();
}
解决方案
You should use this format
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
Which would produce
@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();
}
arg1
will now have your username/value passed.
这篇关于黄瓜方案大纲和通用步骤定义的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文