【问题标题】:Evaluating a expression in quotes failing in robot framework在机器人框架中评估引号中的表达式失败
【发布时间】:2021-01-28 22:13:22
【问题描述】:
*** Variables ***

${text1}      Jack's mother said "Hello" to me 
${text2}      Jack's mother said "Hello" to me

*** Test Cases ***
    ${result}=    Set Variable If    '${text1}' in '${text2}'    ${TRUE}    ${FALSE}

上面的代码给出了错误,因为 Evaluating expression failed: SyntaxError: invalid syntax (, line 1)

单引号导致此问题,但我不想更改变量值并按原样评估它们。用双引号替换也不起作用并给出相同的错误。

有人能建议如何评估吗?

【问题讨论】:

  • 不使用 ' 也会出现同样的错误
  • @Hunter:这是个坏建议,不会解决问题。

标签: python robotframework


【解决方案1】:

您可以通过从变量名中删除花括号来直接在表达式中使用机器人变量。

${result}=    Set Variable If    $text1 in $text2    ${TRUE}    ${FALSE}

这在名为 Evaluating Expressions 的部分下的内置库文档中进行了介绍

【讨论】:

    【解决方案2】:

    您需要使用三引号才能正确转义字符串。这段代码运行良好

       *** Variables ***
        ${text1}      Jack's mother said "Hello" to me
        ${text2}      Jack's mother said "Hello" to me
        
        *** Test Cases ***
        Test
            ${result}=    Set Variable If    '''${text1}''' in '''${text2}'''    ${TRUE}    ${FALSE}
    

    更多信息请看here

    【讨论】:

      猜你喜欢
      • 2019-03-16
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      • 2017-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多