RobotFramework if else
1.在Run Keyword If语句中
如果有多个判断语句,可以用小写 and 或者是 or 连接,具体用 and 还是 or 根据自己程序的情况而定
如果判断后要执行多个语句
则需要使用大写 AND 配合 Run Keywords 使用
2、不久又遇到一个问题,我if 条件后面需要接多个执行语句,还记得当时自己猜测乱写:run keyword if +条件 log 1 log 2(结果肯定报错啦),后面没办法想出了一个解决办法是,把多个执行语句封装成一个关键字:run keyword if +条件 +封装的关键字。总感觉肯定还有其他解决办法,就是查不出来,也没问到。终于在一个群里问到解决方法:Run Keyword If 1==1 Run Keywords log 1 AND log 2 。可以看到用到了关键字Run Keywords和AND来处理。
3. https://www.cnblogs.com/labixinxinyexiangyouxiaobai/articles/12760440.html
4.https://www.cnblogs.com/testlife007/p/5029101.html
5. eg
Run keyword if ${2} == ${2}
... Run Keywords Log to console hello world
... AND Keyword1 Pramas1 Params2
... AND Keyword2 Pramas1 Params2
... AND Keyword3 Pramas1 Params2
... AND Keyword3 Pramas1 Params2
6.
Run KeyWord If
${status} | ${value}= | Run Keyword And Ignore Error | My Keyword |
Run Keyword If | ‘${status}’==’PASS’ | Some Action | arg |
Run Keyword Unless | ‘${status}’==’PASS’ | Another Action | My Keyword |
1.单重条件判断
${status} | Set Variable | 1 | |
Run Keyword If | ${status} <= 3 | log | “right” |
… | ELSE | log | “error” |

Run Keyword If | ‘${color}’ == ‘Red’ or ‘${size}’ == ‘Small’ or ‘Design’ == ‘Simple’ | log | “right” |
2.多重条件判断( …ELSE IF … ELSE)
${status} | Set Variable | 1 | ||
Run Keyword If | ${status} < = 3 | log | “right” | |
… | Else If | ${status} > 4 | log | “error” |
… | Else | log | “end” |
3.利用IF关键字给变量赋值
${status} | Set Variable | 1 | ||
${result} | Run Keyword If | ${status} <= 3 | Set Variable | “right” |
… | Else | Set Variable | “error” |
${status} | Set Variable | 1 | |
${result} | Set Variable If | ${status} <= 3 | “right” |
4.unless关键字
Run Keyword Unless | ‘${color}’ == ‘Red’ or ‘${size}’ == ‘Small’ or ‘Design’ == ‘Simple’ | log | “right” |
5. 结合Python语句使用
${data} | Create Dictionary | 1 | use |
${roleId} | Set Variable | 1 | |
Run Keyword If | “${roleId}” in “${data}” | log | “right” |
… | ELSE | log | “error” |
Run KeyWord and Return Status
${status} | Run Keyword And Return Status | checkbox should be selected | id=checked_box | |
${pageCheckedBox} | Run Keyword If | ‘${status}’ == ‘True’ | Set Variable | True |
… | Else | Set Variable | False |