Return results in Robot Framework keyword?

Matilda Owusu Boateng picture Matilda Owusu Boateng · Sep 28, 2011 · Viewed 72.5k times · Source

How can I return the results after running a keyword?

Example:

mykey word [Arguments] input
   ${results}=  getme input

But I want to use these results:

 ${results} = mykey word  newinput

Answer

Bryan Oakley picture Bryan Oakley · Sep 28, 2011

The Robot Framework user's guide describes how to return a value from a keyword. See User keyword return values.

The short version is: set a variable in your keyword, and use the [return] testcase setting to return that variable.

Here's an example:

*** Keywords ***
mykey word
  [Arguments]  ${input}
  ${string}=  set variable  the string is "${input}"
  [return]  ${string}

*** Test Cases ***
Call custom keyword and get result
  ${results}=  mykey word  newinput
  Should be equal    ${results}    the string is "newinput"

Robot also provides several keywords to explicitly return a value from anywhere in a keyword: