robot framework 的关键字Continue For Loop 用法

Continue For Loop关键字就是python的continue的意思,跳出本层循环,继续执行下一个循环。

我先举个栗子:

:FOR    ${index}    IN RANGE    5            
    ${status}=    Run Keyword And Return Status    Page Should Contain    查看更多    #页面是否包含查看更多    
    Run Keyword If    '${status}'=='True'    Run Keywords    Close Window    AND    Continue For Loop

先不管上面具体什么意思,可以看到,for循环里面有个if语句,if +条件+操作+AND+Continue For Loop。然后运行之后,报错,说这个用法无效。

那么使它有效该如何操作,再请看下面的栗子

:FOR    ${index}    IN RANGE    5            
    ${status}=    Run Keyword And Return Status    Page Should Contain    查看更多    #页面是否包含查看更多    
    Run Keyword If    '${status}'=='True'    Continue For Loop

你发现什么了吗,我舍弃了操作。if +条件+Continue For Loop;只有这样才生效。如果这样能完成你脚本的逻辑,也是可以的,但是如果不能的话,就应该转换另外一种方式。

我之前的博客提到过,if条件后面接操作的2种方式。一种是Run Keywords ---AND----;另外一种是把一个条件后面的所有操作全部封装成一个关键字。所有上面栗子应该改为如下:

第一部分

:FOR    ${index}    IN RANGE    5            
    ${status}=    Run Keyword And Return Status    Page Should Contain    查看更多    #页面是否包含查看更多    
    Run Keyword If    '${status}'=='True'    关闭页面

第二部分

关闭页面 (ps:我的关键字)

Close Window

Continue For Loop

原文地址:https://www.cnblogs.com/yaxue/p/7477249.html