【问题标题】:Parameterizing a specflow step with keyword string from example step使用示例步骤中的关键字字符串参数化 specflow 步骤
【发布时间】:2018-05-10 00:01:53
【问题描述】:

我是 specflow 的新手,需要有关以下 specflow 场景的帮助。

Scenario Outline: Error messages validation for maximum allowed term rule
Given a <product>  
When term exceeds the max allowed term 
Then this <errormessage> is displayed

Examples: 
| product    | errormessage                 |
| ProductA   | This is an error message 1   |
| ProductB   | This is an error message 2   |
| ProductC   | This is an error message 3   |

对于最后一步定义“*Then this errormessage is display ”这一步,我想重用现有的绑定方法
"然后显示这个 (.
)"

这种现有的绑定方法将字符串作为参数(预期的错误消息),并根据从被测应用程序中提取的实际消息对其进行断言。

但是当我按原样使用该方法时 - 它无法将错误消息内容作为字符串数组传递。有人可以帮助我了解我需要做什么才能使其正常工作吗?

绑定方法示例如下。 The step then this is shown is not able to identify this binding,要求我写另一个方法。

[Then(@"this ""(.*)"" is displayed")]
public void ThenErrorMessageIsDisplayed(string errorMessage)
{
    var msg = uServiceSupport.GetMessages(responseData);
    var found = new JObject();

    // due to multiple error and warning messages
    foreach (var elem in msg)
    {
        if (elem["message"].ToString().Contains(errorMessage))
            found = (JObject)elem;
    }

    try
    {                
        Assert.IsTrue(found.HasValues, "Check if response has warning/error message");
        Assert.AreEqual(errorMessage, found["message"].ToString(), "Check if the error message is {0}", errorMessage);
    }            
    catch (AssertionException)
    {
        Helper.LogInfo(string.Format("Response:\n {0}", JObject.Parse(responseData)));
        throw;
    }

}

【问题讨论】:

  • 请发布您现有绑定方法的代码,包括属性和方法签名。这应该可以正常工作
  • 你好@SamHolder 我在下面添加了我现有的绑定示例

标签: specflow


【解决方案1】:

问题出在您的步骤正则表达式中。你有这个:

[Then(@"this ""(.*)"" is displayed")]

但你试着这样称呼它:

Then this <errormessage> is displayed

您没有一致地使用"。你要么需要:

[Then(@"this (.*) is displayed")]

Then this "<errormessage>" is displayed

【讨论】:

  • 谢谢@Sam Holder - 这行得通:)。非常感谢您的帮助
猜你喜欢
  • 2021-05-26
  • 1970-01-01
  • 2014-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多