Search code examples
c#bddspecflowgherkinfeature-file

Getting Multiple matching bindings for two GIVEN having different statements


I've written two Scenario's in Specflow, one for UI and other for API. The scenario's and the step definitions are as follows:

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;
 }

Here, when I navigate to the Step Definition of the Given Statement in the First Scenario, it shows warning for Multiple matching bindings found..and the multiple match bind refers to the step definition of second Given Statement. But I believe since both the Given Statements are different, then why does the first Given throws multiple match bindings ?


Solution

  • The string you have as parameter of the Given- attribute is a regex. And (.*) is catch-all in Regex. So every step that begins with the will be a match for this binding.

    I would suggest you change the step to something line the endpoint with name '(.*)'.

    Also a best practise is to surround your parameters with single quotes '. It's easier to catch parameters and the VS Extension can better suggest binding skeleton code.