string 如何在机器人框架中检查字符串是否包含其他字符串(子字符串)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44496558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:37:15 来源:igfitidea点击:
How to check if a string contains an other string (substring) in robot framework?
提问by Juri
How to check if a string contains an other string in robot framework?
如何检查一个字符串是否包含机器人框架中的另一个字符串?
Something like
就像是
${bool} | String Contains | Hello World | World
Get Substringdoesn't help, because it needs a start index.
Get Substring没有帮助,因为它需要一个起始索引。
采纳答案by Juri
i have found an another solution
我找到了另一个解决方案
${match} | ${value} | Run Keyword And Ignore Error | Should Contain | full string | substring
${RETURNVALUE} | Set Variable If | '${match}' == 'PASS' | ${True} | ${False}
回答by Todor Minakov
${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
Hope the example is self-explanatory
希望这个例子是不言自明的