我正在使用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
場景的重寫看起來同樣喜歡原始方案。減價格式是否刪除了一些字符? –