条件判断
-
RF中用Run Keyword If 关键字做条件判断
1、条件表达式参数给python的eval函数
2、run keyword if '2020' in $html log to console 内容
-
参数放在下一行
run keyword if '2020' in $html and 'UTC' in $html log to console \n2020年的UTC时间
-
ELSE 分支
*** Settings *** Library mylib4 *** Test Cases *** 测试1 ${html}= getwebinfo run keyword if '2019' in $html and 'UTC1' in $html ... log to console \n2019年的,UTC时间 ... ELSE IF 'Jan' in $html log to console Jan11111 ... ELSE log to console ${html}
*** Settings *** Library mylib4 *** Test Cases *** 测试1 #获取接口返回 ${text} getwebinfo #打印变量 log to console ${text} #$text这种写法只能用于python表达式类型的参数中 #如果2020再返回的字符串中,就打印测试通过 run keyword if '2020' in $text and 'UTF' in $text #换行...之后至少空两格 ... log to console 测试通过 ... ELSE IF 'Wed123' in $text log to console 今天是周三 #ELSE不可以小写 ... ELSE log to console 测试不通过
-
循环里面的判断
*** Settings *** Library mylib4 Library Dialogs *** Test Cases *** 测试1 FOR ${i} IN RANGE 99 #获取用户输入 ${score} get value from user 请输入成绩 continue for loop if $score == 'cont' Exit For Loop if $score == 'over' run keyword if int($score) >= 60 log to console 及格了 ... ELSE log to console 不及格 END
-
collection标准库
1、针对List 和 Diction的处理
2、创建并添加元素
3、数字变量${1} ${2}*** Settings *** Library Collections *** Test Cases *** 测试1 ${list} create list 1 2 3 append to list ${list} d e f log to console ${list} ${d} create dictionary a=1 b=2 c=3 set to dictionary ${d} e=4 f=5 # log to console ${d} ${l2} evaluate [i for i in range(100)] log to console ${l2}
-
Evaluate
1、直接用python代码表达式生成一个结果${var}= set variable ${890}
完全可以写成
${var}= evaluate 890
2、复杂的表达式
${var}= evaluate ['hello']*10