Given two strings 'a' , 'b', what is the simplest way to concatenate them and assign to a new variable in robot framework.?
I tried this simple pythonic way, but it didn't work
${var}= 'a' + 'b'
Given two strings 'a' , 'b', what is the simplest way to concatenate them and assign to a new variable in robot framework.?
I tried this simple pythonic way, but it didn't work
${var}= 'a' + 'b'
You can use Catenate from BuiltIn.
Example from docs:
${str1} = Catenate Hello world
${str2} = Catenate SEPARATOR=--- Hello world
${str3} = Catenate SEPARATOR= Hello world
=>
${str1} = 'Hello world'
${str2} = 'Hello---world'
${str3} = 'Helloworld'
Catenate is the usual way to go with strings, as pointed in the other answer.
Alternative option is to use just Set Variable:
${a}= Set Variable First
${b}= Set Variable Second
${c}= Set Variable ${a}${b}
Log To Console ${c} # prints FirstSecond
${c}= Set Variable ${a} ${b}
Log To Console ${c} # prints First Second
${c}= Set Variable ${a}-/-${b}
Log To Console ${c} # prints First-/-Second
The explaination is that the RF processing of any keyword's arguments - Set Variable including, goes through substituting any variable with its value. E.g. for this call:
Set Variable ${a}-/-${b}
What roughly happens is "the end value is the value of variable a-/-the value of variable b".
In Variable part, I used the most simple interpolation
${a} Hello
${b} World
${c} ${a}${b}
If you need to assign the result to a variable that you use only once, you could instead do an inline expression e.g. using Python's str.join(), directly where you would use that variable. Catenate ultimately uses str.join().
${a} Set Variable Hello
${b} Set Variable World
Some keyword ${{ " ".join([$a, $b]) }}
Some keyword ${{ "\n\n".join([$a, $b]) }}
Note: This applies to RF 3.2 and higher.