How to get Returned value from a Keyword called under Run Keyword If in Robot Framework?

霸气de小男生 提交于 2021-02-19 08:21:33

问题


I have written a keyword for Testcase teardown in my Robot Testsuite. Which is mentioned below:

*** Keyword ***
Result Evaluation
@{TRACEFILE} =  evalVirdict  ${value[2]}
:FOR  ${ELEMENT}  IN  @{TRACEFILE}
\    Log  ${ELEMENT}
\    Run Keyword if  '${TEST STATUS}'=='FAIL'  readerrlines  ${ELEMENT}

In the above Keyword evalVirdict is a function written in python and ${value[2]} is coming from my Testcases and in Run Keyword if '${TEST STATUS}' == 'FAIL' readerrlines ${ELEMENT} part. I am calling another function readerrlines which returns some value. The readerrlines function definition is below:

def readerrlines(tracefile):
    errVal = []
    for line in list(open(tracefile)):
        line = line.strip()
        mat = re.match(r'.*\s.*\s+:\s\*+(.*\s)\s{1}', line)
        if mat:
            err = mat.group(1).strip()
            errVal.append(err)
    return errVal

Here i want to know how to get this returned value from readerrlines functions in Run Keyword if '${TEST STATUS}' == 'FAIL' readerrlines ${ELEMENT} ?

I have tried Run Keyword if '${TEST STATUS}' == 'FAIL' @{errval} = readerrlines ${ELEMENT} but got an error as Non-Existing variable @{errval} and also Run Keyword if '${TEST STATUS}' == 'FAIL' Set Variable @{errval} = readerrlines ${ELEMENT} with no error and no output as well.


回答1:


Run Keyword If will return the result of the keyword it is running. Thus, you would do:

${result}=    Run Keyword If    '${TEST STATUS}'=='FAIL'  readerrlines  ${ELEMENT}


来源:https://stackoverflow.com/questions/31249339/how-to-get-returned-value-from-a-keyword-called-under-run-keyword-if-in-robot-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!