2017-10-14 17 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的表達。