Specflow: using same step definition for scenario and scenario outline

时间:2015-11-12 11:07:24

标签: cucumber specflow gherkin

My feature file contains a 'scenario' test for a successful login and a 'Scenario Outline' test for testing multiple login details which should be unsuccessful.

@web
Scenario: Successful login
    Given I have entered username 'tomsmith' and password 'SuperSecretPassword!' into the application
    When I login
    Then I should be informed that login was successful

@web
Scenario Outline: Unsuccessful login
    Given I have entered username <username> and password <password> into the application
    When I login
    Then I should be informed that login was unsuccessful

    Examples: 
    | testing                          | username | password             |
    | invalid combination 1            | test     | test                 |
    | special characters               | $$$      | SuperSecretPassword! |

I would like both to use the same step definition (as they are just passing parameters)

My step definition is:

[Given(@"I have entered username '(.*)' and password '(.*)' into the application")]
public void GivenIHaveEnteredUsernameAndPasswordIntoTheApplication(string p0, string p1)
{
    login = new LoginPage();
    login.with(p0, p1);
}

The problem is that the scenario outline tests do not run, they return a 'Pending' error: Pending: No matching step definition found for one or more steps

and suggests the step definition should be:

[Given(@"I have entered test and test into the application")]

Can anyone help please?

1 个答案:

答案 0 :(得分:3)

you problem is on this line:

Given I have entered username <username> and password <password> into the application

it should be

Given I have entered username '<username>' and password '<password>' into the application

you just missed out the ' marks