I am new to specflow, want help with a specflow scenario like the one below.
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 |
For the last step definition "*Then this errormessage is displayed " step, I want to reuse an existing binding method
"Then this (.) is displayed"
This existing binding method takes a string as a parameter (expected error message) and asserts it against the actual message picked form the app under test.
But when I use the method as is - its unable to pass the error message content as an array of strings . Would someone be able to help me to understand what do I need to do to make it work ?
Binding method example below . The step Then this is displayed is not able to recognize this binding, its asking me to write another method.
[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;
}
}