4

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.

Ramkrishna Sharma
  • 6,961
  • 3
  • 42
  • 51

4 Answers4

1

Probably did not recognized the VS integration the parameter correctly as you created it. Simply change your binding to following:

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

See http://www.specflow.org/documentation/Step-Definitions/ for more information about step bindings.

Andreas Willich
  • 5,665
  • 3
  • 15
  • 22
0

First up, I do not use the Example tag, I do use tables in my tests.

The way I would do this is:

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

Then, create a new class file and call it whatever you want, I name it Paremeters.cs

In this class file, create a public string. For this example I would say:

public string EmailAddress { get; set; }

Now fill in your method for the table:

 [Given(@"I enter an invalid worker email address invalidaddress")]
public void GivenIEnterAnInvalidWorkerEmailAddressInvalidaddress(Table table)
{
    var parameters = table.CreateSet<Parameters>();
    foreach (var parameter in parameters){
         Define your action here what you want to do with each email address
    }
}

Hope this helps :-)

Anand
  • 1,899
  • 1
  • 13
  • 23
  • Using tables and having not separate tests for different cases is a bad idea. You don't see easily which of the cases is failing – Andreas Willich Mar 25 '16 at 12:02
  • I am just helping with a solution for his problem, the parameters :) How to and not to use Specflow is a different discussion – Anand Mar 25 '16 at 12:33
0

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"
alansiqueira27
  • 8,129
  • 15
  • 67
  • 111
-1

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>'