[英]How to accommodate specflow step definition to accept deferent number of parameters from specflow feature file with one method
Hi I have below Specflow feature files嗨,我有以下 Specflow 功能文件
First scenario第一种情况
Scenario outline:
Given Add two numbers <num1> <num2> <num3>
Then divide by <num4>
Examples:
|TestCase|num1|num2|num3|num4|
|Add |1 |2 |3 |4 |
Second Scenario:第二种情况:
Scenario outline:
Given Add two numbers <num1> <num2>
Then divide by <num4>
Examples:
|TestCase|num1|num2|num4|
|Add |1 |2 |4 |
below is the code which I want in Step definition method下面是我在步骤定义方法中想要的代码
[Given(@"Add two numbers (.*) (.*) (.*)")]
[Given(@"Add two numbers (.*) (.*)")]
public void Testtheconditionwith(string a, string b, string c = null)
{
}
this is not working.这是行不通的。 I don't want to write different methods with different parameters.
我不想用不同的参数编写不同的方法。 Is there any way to achieve this?
有什么办法可以做到这一点?
Thanks.谢谢。
SpecFlow doesn't support optional parameters in the step definition methods. SpecFlow 不支持步骤定义方法中的可选参数。 You have to write two methods, but you can simply call one from the other.
您必须编写两种方法,但您可以简单地从另一个中调用一个。
[Given(@"Add two numbers (.*) (.*) (.*)")]
public void Testtheconditionwith(string a, string b, string c)
{
}
[Given(@"Add two numbers (.*) (.*)")]
public void Testtheconditionwith(string a, string b)
{
Testtheconditionwith(a,b,null)
}
Better would be to use the Driver pattern.最好使用 Driver 模式。 More about it at: https://docs.specflow.org/projects/specflow/en/latest/Guides/DriverPattern.html
有关它的更多信息,请访问: https://docs.specflow.org/projects/specflow/en/latest/Guides/DriverPattern.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.