Search code examples
specflowgherkinfeature-file

How to use numbers just as a description in Specflow Feature file instead of a parameter


I'm writing my feature file SpecFlow and I'm looking to use numbers as a just a description. For example :

Given Site is displayed
When I check column1
And column2  
Then values are correct. 

However in the word column1, 1 is actually read as a parameter instead of a description and the method generated for the line is column(.*) instead of column1. And because of this, since I have another line for column2, only 1 method is generated for then "When" & "And" statement.

This is incorrect as I would need to check the elements for both column1 and column2. Is there a way for us to just use numbers as description in the feature file instead of parameters?


Solution

  • You can either modify the step definition or surround the column name in double quotes.

    Option A) Modify the step definition:

    [When(@"I check ([^ ]+)$")]
    public void WhenICheckColumn(string columnName)
    {
        // Check the column
    }
    

    Option B) Surround column name in double quotes

    Change the step itself:

    When I check "column1"
    

    Then change the step definition to:

    [When(@"I check ""(.*)""")]
    public void WhenICheckColumn(string columnName)
    {
        // Check the column
    }