RobotFramework中的嵌套循环 [英] Nested loop in RobotFramework
问题描述
我需要在Robot框架中创建一个嵌套循环. 你能帮我吗?
I need to create a nested loop in Robot framework. Can you please Help me do it?
${contents}= Get File ${file path}
@{lines}= Split to lines ${contents}
${matched elements}= Get Webelements ${LABEL PORTAIL XPATH }
: FOR ${element} IN @{matched elements}
\ ${text}= Get Text ${element}
\ : FOR ${line} IN @{lines}
\ Run Keyword If '${text}' == '${line}' Log '${text} matched'
我需要一个嵌套循环,该循环将文件中的所有${text}
与所有@{lines}
进行比较.
I need to have a nested loop which compares all the ${text}
with all the @{lines}
in the file.
预先感谢
推荐答案
RF中没有嵌套循环.只能通过在外部的内部循环调用一个关键字来完成此操作.
No nested loops in RF; that can be done only by calling a keyword with the inner loop, in the outer one.
但是在您的特定情况下,您可以不使用它-因为要匹配整行,可以通过应包含"来实现:
In your particular case though, you could go without it - as you want to match the full line, that's doable through Should Contain:
${contents}= Get File ${file path}
@{lines}= Split to lines ${contents}
${matched elements}= Get Webelements ${LABEL PORTAIL XPATH }
: FOR ${element} IN @{matched elements}
\ ${text}= Get Text ${element}
\ ${present}= Run Keyword And Return Status Should Contain ${lines}
${text}
\ Run Keyword If ${present} Log '${text} matched'
如果要进行部分比赛-即${text}
成为${lines}
成员的一部分,那么就不可能这样.
If you were going after a partial match - i.e. ${text}
to be a part of a ${lines}
member, then it wouldn't be possible like this.
这篇关于RobotFramework中的嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!