Scenario Outline generating incorrect step code

Viewed 1123

I have the following feature file Feature: Employee_EditEmployeeFeature Check Edit Employee Page

@Employee_EditEmployeeFeature
Scenario Outline: Verify invalid format field error displayed (Email Address)
    Given I enter an invalid worker email address <EmailAddress>
    When I click on the Employee Edit Save button
    Then Check invalid format error displayed for worker Email Address field
Examples: 
| EmailAddress             |
| invalidaddress           |
| invalid address@acme.com |
| invalidaddress@acme      |

@Employee_EditEmployeeFeature
Scenario Outline: Verify invalid format field error displayed (Passport Number)
    Given I enter invalid worker passport number <PassportNo>
    When I click on the Employee Edit Save button
    Then Check invalid format error displayed for worker passport field
Examples:
| PassportNo |
| 1234       |
| AS1234567  |

I get the following step code generated for the Given statements

    [Given(@"I enter an invalid worker email address invalidaddress")]
    public void GivenIEnterAnInvalidWorkerEmailAddressInvalidaddress()
    {
        ScenarioContext.Current.Pending();
    }

    [Given(@"I enter invalid worker passport number (.*)")]
    public void GivenIEnterInvalidWorkerPassportNumber(int p0)
    {
        ScenarioContext.Current.Pending();
    }

Because the email address step has been generated incorrectly e.g. with no parameter, when the test is run it fails with the following, Test Name: VerifyInvalidFormatFieldErrorDisplayedEmailAddress_Invalidaddress Result Message: Assert.Inconclusive failed. No matching step definition found for one or more steps.

using System;
using TechTalk.SpecFlow;
namespace MyNamespace
{
    [Binding]
    public class StepDefinitions
{
[Given(@"I enter an invalid worker email address invalidaddress")]
public void GivenIEnterAnInvalidWorkerEmailAddressInvalidaddress()
{
    ScenarioContext.Current.Pending();
}

I have trawled the internet and see other people have had this issue, and I have tried some of their solutions to no avail. Any advice as I cannot really move on until I can consistently generate correct step code for Scenario Outline features.

4 Answers

After a long time searching, I discovered that we need to use double quotes.

Instead of:

<myParameter>

Use:

"<myParameter>"

Instead of:

When I have a name 'name'

Use:

When I have a "name"

I have encountered the same issue. If you want your steps to be generated correctly after you write down your feature file, on examples leave only the headers then generate your steps and you will see the change.

Your Feature:

@Employee_EditEmployeeFeature
Scenario Outline: Verify invalid format field error displayed (Email Address)
Given I enter an invalid worker email address <EmailAddress>
When I click on the Employee Edit Save button
Then Check invalid format error displayed for worker Email Address field

Examples:

| EmailAddress             |

Your steps generated will look like this

        [Given(@"I enter an invalid worker email address (.*)")]
    public void GivenIEnterAnInvalidWorkerEmailAddress(string p0)
    {
        ScenarioContext.Current.Pending();
    }

    [When(@"I click on the Employee Edit Save button")]
    public void WhenIClickOnTheEmployeeEditSaveButton()
    {
        ScenarioContext.Current.Pending();
    }

    [Then(@"Check invalid format error displayed for worker Email Address field")]
    public void ThenCheckInvalidFormatErrorDisplayedForWorkerEmailAddressField()
    {
        ScenarioContext.Current.Pending();
    }

After the steps are generated you can add your data rows.

Or just decorate your parameters with single quotes

Given I enter an invalid worker email address '<EmailAddress>'
Related