How to check if a string contains an other string in robot framework?
Something like
${bool} | String Contains | Hello World | World
Get Substring doesn't help, because it needs a start index.
You can use contains(), indexOf() and lastIndexOf() method to check if one String contains another String in Java or not. If a String contains another String then it's known as a substring. The indexOf() method accepts a String and returns the starting position of the string if it exists, otherwise, it will return -1.
Splits the string using separator as a delimiter string. If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored. Split words are returned as a list.
END Use Run Keyword If in Robot Framework Run Keyword If ${True} Log This line IS executed. Run Keyword If ${False} Log This line is NOT executed. Use Run Keyword Unless in Robot Framework Run Keyword Unless ${True} Log This line is NOT executed. Run Keyword Unless ${False} Log This line IS executed.
The backslash character can be used to escape special characters so that their literal values are used. For example, if you have a variable that contains the value ${my_variable} , you will need to escape it with the backslash character: \${my_variable} before using it as an argument for a keyword.
${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
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With