I use Run Keyword Unless
comparing a variable and a string:
Run Keyword Unless '${text}' == 'HelloWorld' My Keyword ${text}
Sometimes ${text}
consists of two lines separated by "\n" (eg. "One line\ntwo lines"). If so, the tests fails with an error:
Evaluating expression ''One line
two lines' == 'HelloWorld'' failed: SyntaxError: EOL while scanning string literal (<string>, line 1)
I solved the problem removing '\n' with String.Replace String
as follows:
${one_line_text}= String.Replace String ${text} \n ${SPACE}
Run Keyword Unless '${one_line_text}' == 'HelloWorld' My Keyword ${text}
Is there a way to do it without explicit removing of EOL in a separate keyword?
What about ${text.replace("\n", " ")}
?
You can use python's string literals - """
or '''
- and not change the string at all:
Run Keyword Unless '''${text}''' == 'HelloWorld' My Keyword ${text}
They are designed for pretty much this purpose - to hold values having newline characters, plus quotes.
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