Comment vérifier si une chaîne contient une autre chaîne dans le cadre du robot?
Quelque chose comme
${bool} | String Contains | Hello World | World
Get Substring n'aide pas, car il a besoin d'un index de démarrage.
j'ai trouvé une autre solution
${match} | ${value} | Run Keyword And Ignore Error | Should Contain | full string | substring
${RETURNVALUE} | Set Variable If | '${match}' == 'PASS' | ${True} | ${False}
${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
J'espère que l'exemple va de soi
À partir de l'utilisation de la bibliothèque de chaînes, Get Lines Containing String
, doc ici . Vérifiez ensuite le résultat.