我正在使用specflow
来使用Gherkin
语法编写我的浏览器测试。我有一个步骤定义,我想匹配2个不同的步骤,但不捕获它。对于如:正则表达式匹配黄瓜但不捕获它
Scenario:
Given I have some stuff
And I click on the configure user
And I configure user
And I set the user <config> to <value>
Then I should see user configuration is updated
Scenario:
Given I have some stuff
And I click on the configure admin
And I configure admin
And I set the admin <config> to <value>
Then I should see user configuration is updated
步骤定义的正则表达式And I set the admin <config> to <value>
会是这样的:
Given(@"And I set the admin (.*) to (.*)")
public void AndISetTheAdminConfigToValue(string config, string value)
{
// implementation
}
而对于And I set the user <config> to <value>
会是这样:
Given(@"And I set the admin (.*) to (.*)")
public void AndISetTheUserConfigToValue(string config, string value)
{
// implementation
}
的两个步骤的实现是一样的。所以我想这样做是:
Given(@"And I set the user|admin (.*) to (.*)")
public void AndISetTheConfigToValue(string config, string value)
{
// implementation
}
上面的代码将无法正常工作config
和value
参数会随着user
和admin
被捕获的第一个2个参数空字符串。
有没有办法做到像上面这样的事情,而不捕获参数中的正则表达式匹配?
我知道我可以简单地将情景改写为如下来解决问题。但我只是好奇。
Scenario:
Given I have some stuff
And I click on the configure admin
And I configure admin
And I set the <config> to <value>
Then I should see user configuration is updated
场景的重写看起来同样喜欢原始方案。减价格式是否删除了一些字符? –