在柏树中,如何在步骤实现中传递可选参数
在下面的方案中,“模型”参数是可选的,因为仅需要一个银行。对于其他银行,我们不需要此模型参数。但是我想制作一个单一的“ when”语法实现,以使其可为所有银行
Scenario Outline : Merchant creates an account in abc bank.
Given I am a merchant
When I create a "<type>" "<bank>" with "<model>"
Then I should receive a response
And I should received expected details
Examples:
|type | bank | model|
|abc | xyz | Test |
步骤实现文件重复使用:
When('I create a {string} {string} with {string}', (type, bank, model) => {
})
In below scenario the "model" parameter is optional because it is only needed for one bank. And for other bank we don't need this model parameter. But I want to make one single "When" syntax implementation to make it resuable for all of the bank
Scenario Outline : Merchant creates an account in abc bank.
Given I am a merchant
When I create a "<type>" "<bank>" with "<model>"
Then I should receive a response
And I should received expected details
Examples:
|type | bank | model|
|abc | xyz | Test |
Step Implementation file:
When('I create a {string} {string} with {string}', (type, bank, model) => {
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为每个银行编写一个单独的方案。不要将您的参数放在功能文件中,将其向下推入步骤定义。用名称区分您的两种类型的银行。
一般而言,不要通过编写涵盖大量用例的大型复杂步骤来提高效率。相反,通过编写许多小简单步骤来清楚和简单。
您无需使用方案大纲,也不需要使用示例。通常,它们使Cukes更难阅读,并且更精确。
从您的问题来看,您可能会出现
要简单得多。
Write a separate scenario for each bank. Don't put your parameters in the feature file push them down into the step definition. Differentiate between your two types of bank with a name.
In general don't try and be efficient by writing big complex steps that cover lots of use cases. Instead be clear and simple by writing lots of small simple steps.
You don't need to use scenario outlines and you don't need to use examples. Generally they make Cukes harder to read and less precise.
From your question you might end up with
Which is much simpler.