【问题标题】:How to check if a string contains an other string (substring) in robot framework?如何检查一个字符串是否包含机器人框架中的另一个字符串(子字符串)?
【发布时间】:2017-11-13 18:14:14
【问题描述】:

机器人框架中如何检查一个字符串是否包含另一个字符串?

类似

${bool} | String Contains | Hello World | World

Get Substring 没有帮助,因为它需要一个起始索引。

【问题讨论】:

  • 这个问题不符合我们坚持的基本最低标准,我们要求提出问题的人创建minimal reproducible example 或至少告知已经尝试过的内容。
  • 我已经更新了这个问题,很难用这个标准来描述这样一个普遍、简单的问题

标签: string robotframework


【解决方案1】:
${source}=    Set Variable    this is a string

# ${contains} will be True if "is a" is a part of the ${source} value
${contains}=  Evaluate   "is a" in """${source}"""

# will fail if "is a" is not a part of the ${source} value
Should Be True      "is a" in """${source}"""

# using a robotframework keyword from the String library
# it is actually a wrapper of python's "var_a in var_b" - the previous approaches
Should Contain    ${source}    is a

# as last alternative - an approach that will store 
# the result in a boolean, with RF standard keywords
# ${contains} will be True if "is a" is a part of the ${source} value
${contains}=    Run Keyword And Return Status    Should Contain    ${source}    is a

希望这个例子是不言自明的

【讨论】:

  • 这应该被接受的答案
【解决方案2】:

我找到了另一个解决方案

${match} | ${value} | Run Keyword And Ignore Error | Should Contain | full string    | substring
${RETURNVALUE} | Set Variable If | '${match}' == 'PASS' | ${True} | ${False}

【讨论】:

    【解决方案3】:

    来自字符串库,使用Get Lines Containing String、doc here。然后检查结果。

    【讨论】:

      猜你喜欢
      • 2013-03-13
      • 2021-05-06
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      相关资源
      最近更新 更多