RF 条件判断 Run Keyword If

Robot Framework 用Run Keyword If 关键字做条件判断

 run keyword if    '123' in $var and '456' in $var    log to console  内容

 run keyword if     条件                                          结果

 

 多行写法,换行时需要加上三个点... 后面的语句必须加上2个以上的空格

${chengji}    get value from user    请输入您的成绩    60
run keyword if    ${chengji}==100
...   log to console    太棒了!
...   ELSE IF   ${chengji} > 80 and ${chengji} < 90   log to console    很好
...   ELSE    log to console   加油哦

注意 *ELSE 和 ELSE  IF 作为run keyword if 的分支,必须大写

 

加入循环的判断

:FOR   ${var}  IN RANGE  5
\  ${chengji}    get value from user    请输入您的成绩    60
\  run keyword if    ${chengji}==100   
\  ...   log to console    太棒了!
\  ...   ELSE IF   ${chengji} > 80 and ${chengji} < 90   log to console    很好
\  ...   ELSE    log to console   加油哦

:FOR   变量  in range  循环次数

get value from user 需要导入库 Dialogs

要加反斜杠 \  用在for循环里 相当于缩进

技巧:多条反斜杠可以按住Alt键下拉出竖线后,点击\键

 

Exit For Loop 与 Continue For Loop

:FOR   ${var}  IN RANGE  10
\  ${chengji}    get value from user    请输入您的成绩    60
\  run keyword if    $chengji=='over'  exit for loop         #  exit for loop 退出循环
\  run keyword if    $chengji=='go on'  continue for loop    # continue for loop
\  run keyword if    int($chengji)==100
\  ...   log to console    太棒了!
\  ...   ELSE IF   int($chengji) > 80 and int($chengji) < 90   log to console    很好
\  ...   ELSE    log to console   加油哦

 

 

你可能感兴趣的:(RobotFramework)