使用示例步骤中的关键字字符串参数化 specflow 步骤
Parameterizing a specflow step with keyword string from example step
我是 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 displayed ”这一步,我想重用一个已有的绑定方法
“然后显示这个 (.)”
此现有绑定方法将字符串作为参数(预期错误消息)并根据从被测应用中选取的实际消息对其进行断言。
但是当我按原样使用该方法时 - 它无法将错误消息内容作为字符串数组传递。有人可以帮助我了解我需要做什么才能让它发挥作用吗?
绑定方法示例如下。 Then this is displayed步骤无法识别此绑定,让我写另一个方法。
[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;
}
}
问题出在您的步骤正则表达式中。你有这个:
[Then(@"this ""(.*)"" is displayed")]
但你试着这样称呼它:
Then this <errormessage> is displayed
您对 "
的用法不一致。你要么需要:
[Then(@"this (.*) is displayed")]
或
Then this "<errormessage>" is displayed
我是 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 displayed ”这一步,我想重用一个已有的绑定方法
“然后显示这个 (.)”
此现有绑定方法将字符串作为参数(预期错误消息)并根据从被测应用中选取的实际消息对其进行断言。
但是当我按原样使用该方法时 - 它无法将错误消息内容作为字符串数组传递。有人可以帮助我了解我需要做什么才能让它发挥作用吗?
绑定方法示例如下。 Then this is displayed步骤无法识别此绑定,让我写另一个方法。
[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;
}
}
问题出在您的步骤正则表达式中。你有这个:
[Then(@"this ""(.*)"" is displayed")]
但你试着这样称呼它:
Then this <errormessage> is displayed
您对 "
的用法不一致。你要么需要:
[Then(@"this (.*) is displayed")]
或
Then this "<errormessage>" is displayed