为两个具有不同语句的 GIVEN 获取多个匹配绑定

我在 Specflow 中编写了两个场景,一个用于 UI,另一个用于 API。场景和步骤定义如下:


Scenario 1:

@Regression

Scenario Outline: Add Single New External User

Given the <role> is logged on to the portal with <email> and <password>

When the <role> clicks on profile avatar

Something....


Scenario 2:

@GetClientList

Scenario Outline: GET API response for fetching list of Clients matching  

criteria entered in the Search Text field

Given the <endpoint>

When I call Get method

Something....


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;

 }

在这里,当我导航到第一个场景中 Given 语句的步骤定义时,它显示找到多个匹配绑定的警告......并且多个匹配绑定引用第二个 Given 语句的步骤定义。但我相信既然两个 Given 语句都不同,那么为什么第一个 Given 会抛出多个匹配绑定?


慕虎7371278
浏览 92回答 1
1回答

慕运维8079593

作为 Given- 属性参数的字符串是一个正则表达式。并且 (.*) 在 Regex 中是包罗万象的。因此,以 开头的每个步骤the都将匹配此绑定。我建议您将 step 更改为 line&nbsp;the endpoint with name '(.*)'。另外一个最佳做法是用单引号将您的参数括起来'。捕获参数更容易,VS 扩展可以更好地建议绑定骨架代码。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go