【问题标题】:Specflow - no matching step definition error but only on second iteration of scenario outlineSpecflow - 没有匹配的步骤定义错误,但仅在场景大纲的第二次迭代中
【发布时间】:2017-08-20 08:41:04
【问题描述】:

我的解决方案中有一个功能如下:

特点:登录
登录屏幕
场景大纲:使用无效凭据登录
鉴于已创建并激活用户帐户
何时 我输入用户名
然后我输入密码
然后我按登录
然后 显示错误消息
示例:
|用户名 |密码 |
|乔.bloggs | abcd1234 |
|已知用户 | CK |

步骤文件包含:

[Binding]
public class LoginSteps
{

    [Given(@"A user account has been created and activated")]
    public void GivenAUserAccountHasBeenCreatedAndActivated()
    {
        int a = 1;
    }

    [When(@"When I enter the username (.*)")]
    public void WhenIEnterTheUsername(string username)
    {
        int a = 1;
    }

    [When(@"When I enter the password (.*)")]
    public void WhenIEnterThePassword(string password)
    {
        int a = 1;
    }

    [When(@"I press Login")]
    public void WhenIPressLogin()
    {
        int a = 1;
    }

    [Then(@"An error message is displayed")]
    public void ThenAnErrorMessageIsDisplayed()
    {
        int a = 1;
    }
}

*我添加了'int a = 1;'临时行以保持调试简单

当我右键单击该功能并选择“调试 Specflow 场景”时,会发生以下错误: 没有为一个或多个步骤找到匹配的步骤定义:“显示一条错误消息”

场景的所有颜色编码正确,转到步骤定义适用于“显示错误消息”步骤。

其他人之前看过这个或有任何关于如何修复的建议?

【问题讨论】:

  • 对不起,我最初粘贴了错误的步骤代码。现在已替换为正确的代码。
  • 能否请您修复场景的格式?

标签: specflow


【解决方案1】:

问题可能在您的 specflow 项目的配置文件中... 你是否: a) 不声明测试运行者 b) 声明一种非英语语言?

或替代 c) 意外禁用 specflow d) 选择了错误的 dotnet-framework

【讨论】:

    【解决方案2】:

    最后,我可以修复它的唯一方法是删除功能文件并从头开始重新创建它。现在可以工作,但我不知道到底是什么问题。

    【讨论】:

      【解决方案3】:

      您遇到的问题是 when 步骤中的单词 when 重复如下:

       [When(@"When I enter the username (.*)")]
      ....
      
       [When(@"When I enter the password (.*)")]
      

      他们应该是这样的:

          [When(@"I enter the username (.*)")]
          public void WhenIEnterTheUsername(string username)
          {
              int a = 1;
          }
      
          [When(@"I enter the password (.*)")]
          public void WhenIEnterThePassword(string password)
          {
              int a = 1;
          }
      

      【讨论】:

        猜你喜欢
        • 2016-02-13
        • 2018-06-20
        • 2018-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-26
        • 2017-03-28
        相关资源
        最近更新 更多