Robot Framework:在实际变量中包含竖线(|)字符而不是作为分隔符的方法?

Robot Framework: Way to include pipe (|) characters in actual variables and not as a separator?

我正在通过带有 .robot 文件设置的文本格式使用 Robot Framework。我一直在寻找一种方法来在变量的每一侧包含一个管道字符 | 和一个 space 作为变量中的可读内容,而不会导致 Robot Framework 将其视为分隔符。问题是 Robot Framework 总是将每边至少有一个 space 的管道字符视为文本格式的分隔符。

我寻找这个的原因是因为在我的测试中,使用 Selenium2Library,我链接的一些页面标题中有管道字符,我需要验证 spaces,最好是确切的文本匹配。

我在 Robot Framework 中的变量如下所示:

| ${MY VARIABLE} | This site | Check it out |

在 python 中,它看起来像这样:

MY_VARIABLE = "This site | Check it out"

上面的变量应该包括竖线字符,但是在 Robot Framework 示例中,中间的竖线字符充当变量中的分隔符(因为它的每一侧都有一个 space,就像其他管道字符分隔符)。

有没有办法告诉 Robot Framework 在内容中包含这个“|”,比如以某种方式包装变量的内容?我试过使用方括号、圆括号和花括号,但似乎没有用。

您可以在管道前加上反斜杠。 robot framework users guide has a section on escaping:

There is no need to escape empty cells (other than the trailing empty cells) when using the pipe and space separated format. The only thing to take into account is that possible pipes surrounded by spaces in the actual test data must be escaped with a backslash

这是一个例子:

*** Variables ***
| ${MY VARIABLE} | THis site \| Check it out

*** Test Cases ***
| Example #1
| | log to console | ${MY VARIABLE}