对于测试,我制作了2个关键字。一般的想法是,如果存在某个字段,字段名和消息,则检查一系列对象。如果字段或字段名不存在,则关键字必须返回到forloop。关键字必须返回${index}
和${result}
。当我运行此测试并且失败时,变量$ {results}显示为${result}=None
,当测试通过时变为${result}= [3, u'PASS']
我认为这与forloop中的${result}=
我尝试了Run keyword and return
但是它没有用,我有点困惑在哪里放${variables}
以及在哪里使用它。
任何人都可以帮我解决这个问题吗?
for循环:
${index}= | set variable | 0
${result}= | Set Variable | not started
: FOR | ${value} | IN RANGE | ${index} | 15
\ ${resultaat}= |"other keyword" | ${index}
\ ${index}= | "keyword add 1 to index" | ${index}
\ Return From Keyword if | '${result}'=='PASS'
${testsuccess}= | Set Variable If | '${result}'=='PASS' | TEST GESLAAGD
'其他关键字'是:
[ARGS] ${index}
${index}= | set variable | ${index}
${check1}= <IS FIELD THERE>
${result}= | set variable if | ${check1}==False | FIELD NOT THERE
return from keyword if | ${check1}=False
${check2}= <HAS FIELD VALUE X>
${result}= | set variable if | ${check2}==False | WRONG VALUE
return from keyword if | ${check2}=False
${check3}= <IS MESSAGE X>
${result}= | set variable if | ${check3}==False | FAIL
${result}= | set variable if | ${check3}==True | PASS
[RETURN] ${index} ${result}
LOG:
keyword = '${result}'=='PASS'
FOR = '${testsucces}=None'
(但这是不对的,因为条件已经满足)
答案 0 :(得分:1)
Set Variable If
会将值设置为None
。请参阅doc:http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Variable%20If
所以改编你的代码:
${result} | Set Variable If | ${check3}==False | FAIL
... | ${check3}==True | PASS
如文档示例所示。
答案 1 :(得分:0)
当我将${result}
放在return from keyword if
例如:
return from keyword if | ${check1}=False | ${result}
答案 2 :(得分:0)
尝试以下代码以在for循环内返回
*** Keywords ***
ReturnFromForLoop
FOR ${i} IN RANGE 1 5
Return From Keyword ${i}
END
ReturnFromForLoopWithIf
FOR ${i} IN RANGE 1 5
Return From Keyword If ${i}==2 ${i}
END