You can create a library with a keyword that will log the return value of Evaluate
, but it will be the same as storing the return value of Evaluate
in the Robot Framework script. So a one liner is possible ${retval}= Evaluate 1 + 2
but in general keywords are not substituted by their return value when passed as a parameter.
from robot.libraries.BuiltIn import BuiltIn
def evaluate_and_log_return_value(expression):
retval= BuiltIn().evaluate(expression)
BuiltIn().log(retval)
The test:
*** Settings ***
Library var.py
*** Test Cases ***
Test 1
Evaluate And Log Return Value 1 + 2
Test 2
${retval}= Evaluate 1 + 2
You can check the output to see that basically the two are the same because variable assignments are logged by default. You do not have to call Log
again if you are interested in the value of the assigned variable.
You can write a general keyword as well that will take any keyword by name with its arguments, it will execute it and log the return value.
from robot.libraries.BuiltIn import BuiltIn
def run_keyword_and_log_return_value(keyword, *args):
BuiltIn().log(BuiltIn().run_keyword(keyword, *args))
Example:
*** Settings ***
Library var.py
*** Test Cases ***
Test 3
Run Keyword And Log Return Value Evaluate 1 + 2
Run Keyword And Log Return Value Set Variable data
Output:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…