2017-10-14 515 views
3

在我的测试情况下,我想比较,如果如何比较在Robot Framework的两个变量如果双引号存在字符串中

'Content-type "application/pdf" is not supported'

存在或不存在。

这个错误我得到:

Evaluating expression '"Content-type "application/pdf" is not supported" != ""' failed: SyntaxError: invalid syntax (, line 1)

我的关键字表达式为:

Run Keyword If "${failure_message}" != "${EMPTY}" My Click Element id=btn_import_cancel 

回答

2

机器人,可以忽略括号使用变量表达式没有引号。

run keyword if $failure_message != "" My Click Element id=btn_import_cancel 

有关更多信息,请参见BuiltIn库文档中的Evaluating Expressions

2

你可以把在三重引号中的变量 - 这就是所谓的一个字符串的蟒蛇,它几乎可以包含所有字符没有问题 - 双引号,\n
例如,对于你的情况:

Run Keyword If """${failure_message}""" != "${EMPTY}" My Click Element id=btn_import_cancel 
# ${EMPTY} is a RF builtin variable, shortcut for an empty string - not needed here, but I guess it helps with the case's readability 

在原来的做法发生了什么事是,RF取代的${failure_message}的价值,因为它有双引号烧焦这有效地关闭封闭报价中途 - 在这里:"Content-type "application
,留下{application}出字符串和“使其” t的操作数他是python的表达。

相关问题