如何从Robot Framework中Run Keyword If下调用的关键字获取返回值? [英] How to get Returned value from a Keyword called under Run Keyword If in Robot Framework?
问题描述
我在我的机器人测试套件中为测试用例的拆卸写了一个关键字.下面提到:
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}
在上面的关键字 evalVirdict
是一个用 python 编写的函数,${value[2]}
来自我的测试用例和 Run Keyword if '${TEST STATUS}' == 'FAIL' readerrlines ${ELEMENT}
部分.我正在调用另一个函数 readerrlines
,它返回一些值.readerrlines
函数定义如下:
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
这里我想知道如何从 Run Keyword if '${TEST STATUS}' == 'FAIL' readerrlines ${ELEMENT}
中的 readerrlines 函数获取这个返回值?
Here i want to know how to get this returned value from readerrlines functions in Run Keyword if '${TEST STATUS}' == 'FAIL' readerrlines ${ELEMENT}
?
我已经尝试过 Run Keyword if '${TEST STATUS}' == 'FAIL' @{errval} = readerrlines ${ELEMENT}
但得到一个错误为非现有变量 @{errval还有 Run Keyword if '${TEST STATUS}' == 'FAIL' Set Variable @{errval} = 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.
推荐答案
Run Keyword If
将返回它正在运行的关键字的结果.因此,你会这样做:
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}
这篇关于如何从Robot Framework中Run Keyword If下调用的关键字获取返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!