场景大纲生成错误的步骤代码

时间:2016-03-25 08:55:30

标签: specflow scenarios

我有以下功能文件     功能:Employee_EditEmployeeFeature         选中编辑员工页面

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

我得到了为Given语句生成的以下步骤代码

    [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();
    }

因为电子邮件地址步骤生成错误,例如没有参数,当测试运行时,它失败并带有以下内容, 测试名称:VerifyInvalidFormatFieldErrorDisplayedEmailAddress_Invalidaddress 结果消息: Assert.Inconclusive失败了。找不到一个或多个步骤的匹配步骤定义。

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();
}

我已经浏览过互联网并看到其他人遇到过这个问题,我尝试了一些他们的解决方案无济于事。任何建议,因为我无法继续前进,直到我能够始终为Scenario Outline功能生成正确的步骤代码。

4 个答案:

答案 0 :(得分:1)

在您创建参数时,可能没有正确识别VS集成参数。 只需将绑定更改为以下内容:

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

有关步骤绑定的详细信息,请参阅http://www.specflow.org/documentation/Step-Definitions/

答案 1 :(得分:0)

首先,我不使用Example标签,我在测试中使用表格。

我这样做的方式是:

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

然后,创建一个新的类文件并随意调用它,我将其命名为Paremeters.cs

在此类文件中,创建一个公共字符串。对于这个例子,我会说:

public string EmailAddress { get; set; }

现在填写表格的方法:

 [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
    }
}

希望这会有所帮助: - )

答案 2 :(得分:0)

经过长时间的搜索,我发现我们需要使用双引号

代替:

<myParameter>

使用:

"<myParameter>"

代替:

When I have a name 'name'

使用:

When I have a "name"

答案 3 :(得分:-1)

我遇到了同样的问题。如果您希望在写下功能文件后正确生成步骤,请在示例中仅保留标题,然后生成步骤,您将看到更改。

您的功能:

@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

示例:

| EmailAddress             |

您生成的步骤将如下所示

        [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();
    }

生成步骤后,您可以添加数据行。

或者只用单引号修饰参数

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