C# 如何在C中传递Specflow中的可选参数#

C# 如何在C中传递Specflow中的可选参数#,c#,selenium-webdriver,specflow,gherkin,C#,Selenium Webdriver,Specflow,Gherkin,我在功能文件中有以下步骤 When I add employee with vendor 'vendorname' And I add employee with vendor 'vendorname' and client 'clientname' 我希望在一个步骤定义中包含这两个步骤,其中客户端名称可以是可选的。 我可以使用两步定义来实现这一点,但它会复制代码。所以你想写这样的东西吗 When I add an employee with the following information

我在功能文件中有以下步骤

When I add employee with vendor 'vendorname'
And I add employee with vendor 'vendorname' and client 'clientname'
我希望在一个步骤定义中包含这两个步骤,其中客户端名称可以是可选的。
我可以使用两步定义来实现这一点,但它会复制代码。

所以你想写这样的东西吗

When I add an employee with the following information
| vendor     | client     |
| vendorname | clientname |
这将生成带有表参数的步骤定义


您可以自己旋转表格,或使用表格CreateInstance、CreateInstance、CreateSet、CreateSet的帮助函数将表格映射到测试中的对象。

SpecFlow不支持可选参数。
为此,您需要单独的步骤


但是我们为此欢迎PRs:

好吧,我想你可以做一些事情,这取决于你想要实现什么或者你希望你的代码是什么样子。现在我脑子里有一件事

例如,而不是:

When I add employee with vendor 'vendorname'
And I add employee with vendor 'vendorname' and client 'clientname'
你可以写下:

When I add employee with vendor 'vendorname' and client 'clientname'
或者,采用与Fran建议相同的方法:

When I add an employee with the following information
| vendor     | client     |
| vendorname | clientname |

然后,当您在.feature文件的步骤中设置输入参数时,您可以选择要在步骤定义文件中查询的任何预定义字符串或值(使用if或switch语句)。

行尾只能有一个可选参数。使用非捕获组

[当(@“我向供应商(.*)(:和客户(.*))添加员工时]
public void iaddemptoye(字符串vendorName,字符串clientName=null)
{
}

重新编写使用SpecFlow的步骤