我在 Specflow 中編寫了兩個場景,一個用于 UI,另一個用于 API。場景和步驟定義如下:Scenario 1:@RegressionScenario Outline: Add Single New External UserGiven the <role> is logged on to the portal with <email> and <password>When the <role> clicks on profile avatarSomething....Scenario 2:@GetClientListScenario Outline: GET API response for fetching list of Clients matching criteria entered in the Search Text fieldGiven the <endpoint>When I call Get methodSomething....Step Definitions:[Given(@"the (.*) is logged on to the portal with (.*) and (.*)")]public void GivenLoginToPortal(string role, string email, string password) { //Something }[Given(@"the (.*)")]public void GivenTheEndpoint(string endpoint) { Endpoint = endpoint; }在這里,當(dāng)我導(dǎo)航到第一個場景中 Given 語句的步驟定義時,它顯示找到多個匹配綁定的警告......并且多個匹配綁定引用第二個 Given 語句的步驟定義。但我相信既然兩個 Given 語句都不同,那么為什么第一個 Given 會拋出多個匹配綁定?
1 回答

慕運維8079593
TA貢獻(xiàn)1876條經(jīng)驗 獲得超5個贊
作為 Given- 屬性參數(shù)的字符串是一個正則表達(dá)式。并且 (.*) 在 Regex 中是包羅萬象的。因此,以 開頭的每個步驟the
都將匹配此綁定。
我建議您將 step 更改為 line the endpoint with name '(.*)'
。
另外一個最佳做法是用單引號將您的參數(shù)括起來'
。捕獲參數(shù)更容易,VS 擴(kuò)展可以更好地建議綁定骨架代碼。
- 1 回答
- 0 關(guān)注
- 82 瀏覽
添加回答
舉報
0/150
提交
取消