Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return two values in Robot Framework

Is there a possibility to return two variables in Robot Framework?

${result1}, ${result2}=    MyKeyword

doesn't work.

like image 878
kame Avatar asked Jul 18 '16 15:07

kame


People also ask

How do I return two values in Robot Framework?

There cannot be more than 1 space between the '=' and the variable to its left (zero spaces are fine as well). Any more spaces results in Robot treating the equal sign as a distinct keyword (which will fail).

Can you return 2 values in function?

No, you can not have two returns in a function, the first return will exit the function you will need to create an object.

Can we return 2 variables?

You cannot explicitly return two variables from a single function, but there are various ways you could concatenate the two variables in order to return them.

How do you use return in Robot Framework?

The short version is: set a variable in your keyword, and use the [return] testcase setting to return that variable. Robot also provides several keywords to explicitly return a value from anywhere in a keyword: Return from keyword. Return from keyword if.


2 Answers

Yes, just place the variables in separate cells, both when assigning and when returning the values.

For example:

*** Test Case ***
Example
    ${value1}    ${value2}    return two values
    Should be equal    ${value1}    this is value 1
    Should be equal    ${value2}    this is value 2


*** Keywords ***
Return two values
    ${v1}=      set variable    this is value 1
    ${v2}=      set variable    this is value 2

    [Return]    ${v1}    ${v2} 
like image 57
Bryan Oakley Avatar answered Sep 28 '22 06:09

Bryan Oakley


Remove the ,

${result1}    ${result2}    =    MyKeyword
like image 36
shicky Avatar answered Sep 28 '22 07:09

shicky