SpecFlow: Scenario Outline Examples

SpecFlow does handle string parameters by default, the problem is that you left control up to SpecFlow in determining at runtime what your values are.

When you ran "Generate Step Definitions," you selected "Method name - underscores" in the Style dropdown. This left interpreting the input parameters up to SpecFlow, which will create what are called 'greedy' regular expressions to identify the parameter values. This means that it would include the comma as part of the value.

Had you selected "Regular expressions in attributes," (or refactored your code a touch and decorated your attributes by hand) your step could look like this:

[Given(@"I have completed the form with (.*), (.*), (.*), and (.*)")]
public void Given_I_have_completed_the_form_with(string email, string org, string pwd, string conf)
{
    //do stuff here
}

This creates a more 'parsimonious' expression that tells SpecFlow to accept strings of any length, up to but not including any trailing commas. Single quotes around the regular expressions would make it even more explicit:

[Given(@"I have completed the form with '(.*)', '(.*)', '(.*)', and '(.*)'")]

Managing the regular expressions yourself can create headaches, but it really exposes the full power of SpecFlow if you do so.


RESOLVED - It was not an issue with the use of characters such as @ or &. It was actually using commas in my Given Statement. I found if I used 'and' it works. So to get it working the statement had to be written as below: -

SOLUTION

  1. Write statement as

    Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>

  2. Modify statement to put single quotes around paramaters that need to be strings

    Given I have completed the form with '<email>' and '<organisation>' and '<password>' and '<passwordConfirmation>'

  3. Generation Step Definitions and then change statement back to exclude single quotes

    Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>

A bit of mucking around but it gets the correct results. Hopefully in the future SpecFlow will be updated to handle paramaters as strings as default.