robotframework

How to use both Run Keyword If and Run Keyword and Return Status?


file.robot
Keyword1
       log  this is keyword1
       ${some_value} =  Set Variable    Hello, world!
       [Return]   ${some_value}

file2.robot
Some_name
        Run keyword If    'True' == 'True Run Keyword and return Status   Keyword1

I want to use this way. How do i access the return value in file2.robot

Above, 'Some_name' in file2.robot calls the 'Keyword1', the return value 'some_value' to be printed in 'Some_name' of file2.robot.

How can it be achieved in one-liner as stated above ?


Solution

  • You cannot use a "Run keyword..." command and both get a return value and a pass/fail value. However, if all you need is the return value, Run keyword if will return the result of the keyword that it runs.

    For example:

    *** Test Cases ***
    Example
        ${the_value}=  run keyword if  'True' == 'True'  keyword 1
    

    With the above, keyword 1 will only run if the expression evaluates to true. ${the_value} will be set to the result of keyword 1.

    If you need both the status and the returned value, you can use Run keyword and return status to run the keyword, but you'll have to modify the keyword to set a suite or global variable that your test can get after the keyword returns.