RobotFramework基本语法----IF语句

if语句通过run Keywords以达到语句块功能
run keyword if     '${type1}'=='1' and '${type2}'=='2'    run Keywords    should be true    '${status1}'=='enable'
...    AND    should be true    '${status2}'=='enable'
...    AND    should be true    '${status3}'=='enable'
 
判断满足条件1后,进一步判断满足条件2后,设置flag变量值为true
${flag}    runkeyword if    条件1    set variable if    条件2    True
 
由于flag变量多次判断,第一次判断成功后,会给flag赋值0。如果利用这种写法,通过Exit For Loop跳过后续if语句,那么后续不满足条件会将flag变量置位NONE,覆盖flag=0,导致后续用到flag的地方出错。
FOR ${i} IN RANGE 1
    ${flag}     run keyword if     '${device_mode}'=='VSC'     set variable if     ${maincard_shelfid}==0     0
    runkeywordif     '${flag}'=='0'     Exit For Loop
    ${flag}     run keyword if     '${device_mode}'=='VSC'     set variable if     ${maincard_shelfid}==1     1
    runkeywordif    '${flag}'=='1'     Exit For Loop
    ${flag}     run keyword if     '${device_mode}'=='ALONE'     set variable     2
    runkeywordif     '${flag}'=='2'     Exit For Loop
END
 
RF不支持if判断内嵌FOR语句体,如果需要这么写,可以将FOR语句块定义为一个关键字,判断条件满足时,执行该关键字以达到IF语句嵌套FOR语句
 
if-elseif-else语法:
run keyword if    ${flag}==0    堆叠写入 device=${device}    online_power_list=${online_power_list}    powerPn=${powerPn}
...    ELSE IF    ${flag}==1     堆叠写入 device=${device}    online_power_list=${online_power_list}    powerPn=${powerPn}
...    ELSE IF    ${flag}==2    普通写入 device=${device}    online_power_list=${online_power_list}    powerPn=${powerPn}
...    ELSE
posted @   飞虎就是我  阅读(1438)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示