RobotFramework 中的嵌套循环 [英] Nested loop in RobotFramework

查看:57
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆