如何验证 Specflow 中两行的成功文本消息

How to validate a success text message which is in two lines in Specflow

我正在尝试验证应用程序在创建或删除值后生成的消息。

我尝试从应用程序捕获输入,应用程序的成功消息如下:-

示例:

"This is a -\r\nText Message."

我在 specflow 中的输入:-

Then user verifies "This is a -r nText Message." ->Does not work

也试过了-

Then user verifies "This is a -\r\nText Message." ->Does not work and returns text "This is a -\\r\\nText Message."

请帮忙。

HTML 代码:-

<article class="alertify-log alertify-log-success alertify-log-show">
    This is a -
    <br>
    Text Message.
<article/>

我的代码:

[FindsBy(How = How.XPath, Using = "//article[@class='alertify-log alertify-log-success alertify-log-show']")]
public IWebElement AlertMessage;

public static void(string Message)
{
    string VerifyMessage = commonPage.AlertMessage.Text;
    Assert.AreEqual(Message, VerifyMessage);
    Console.WriteLine(VerifyMessage );
}

我会做一个替换。

var test = Driver.FindElement(By.XPath("//article[@class='alertify-log alertify-log-success alertify-log-show']")).Text.Replace("-\r\n", "");

这将 return:

    "This is a Text Message."

所以在你的代码中,试试这个:

更改您的步骤以查找没有“-\r\n”的文本

var Message = "This is a Text Message.";  

[FindsBy(How = How.XPath, Using = "//article[@class='alertify-log alertify-log-success alertify-log-show']")]

public IWebElement AlertMessage;

public static void(string Message)
{
string VerifyMessage = commonPage.AlertMessage.Text.Replace("-\r\n", "");
Assert.AreEqual(Message, VerifyMessage);
Console.WriteLine(VerifyMessage );
}

您可以使用 DocString (https://docs.specflow.org/projects/specflow/en/latest/Gherkin/Gherkin-Reference.html#doc-strings) 参数代替普通参数。这样,您可以指定多行字符串

你的步骤看起来像这样:

Then user verifies 
    """
    This is a
    Text Message.
    """

您可以将此多行字符串作为普通参数访问:

[Then("user verifies")]
public void BindingMethod(string parameter)
{
    //your code
}