如何在SpecFlow中比较多行参数?

问题描述

我有一个带有步骤的功能文件

Then I must see the specific text 'Lorem ipsum.\r\nLorem ipsum,lorem ipsum - lorem ipsum\r\nLorem ipsum.' in the text .error-message block on the page

步骤定义

    [Then(@"I must see the specific text '(.*)' in the text (.*) block on the page")]
    public void ThenISeeTheSpecificTextOnThePage(string expectedText,string textBlockName)
    {
        var actualText = driver.FindElement(By.CssSelector(textBlockName)).Text;
        ///var removeCaret = actualText.Replace(Environment.NewLine,string.Empty);
        Assert.Contains(expectedText,actualText);
    }

每次我在调试中运行此步骤时,我都会看到输出

> Assert.Contains() Failure
Not found: Lorem ipsum. Lorem ipsum,Lorem ipsum
In value:  Lorem ipsum.
Lorem ipsum,Lorem ipsum
Lorem ipsum

我知道我可以修整\r\n并在功能文件中调整我的输入参数。但这将是一个hack,我不想这么做。有机会断言多行文字吗?

解决方法

您可以使用Doc Strings来指定您的字符串参数:

aes

并使用以下步骤定义:

ggplot