用户关键字
Keywords 中定义关键字,有以下代码中六种形式:
*** Keywords ***
关键字-无参
log to console step1
log to console step2
带参关键字-传参
[Arguments] ${date}
log to console Today is ${date}
带参关键字-默认参数
[Arguments] ${date}=周末
log to console ${date}休息
带参关键字-多个参数
[Arguments] @{fruit}
log to console 水果:${fruit}
带参关键字-键值对参数
[Arguments] &{citys}
FOR ${city} IN @{citys}
log to console 省与省会: ${city}-${citys}[${city}]
END
带参关键字-返回值
${score} get value from user 请输入分数 #引入Library Dialogs
${res} set variable if int(${score})>60 ELSE 不通过
[Return] ${res}
log to console ${res}
使用关键字的时候,直接在用例中引入关键字
*** Test Cases ***
case1
关键字-无参
带参关键字-传参 2021-3-5
带参关键字-默认参数
带参关键字-多个参数 苹果,香蕉,西瓜,橙子
带参关键字-键值对参数 四川=成都 江苏=南京 西藏=拉萨
带参关键字-返回值
打印结果:
注:第六种情况会弹出对话框,输入分数做判断
数据驱动
在RF种用不起来,因为不够灵活,参数必须写在用例中,无法像pytest那样读取yaml文件、excel文件
数据驱动原则:
即使某组参数导致用例失败,也不影响后续参数的执行,同时测试结果能够显示出来
*** Test Cases ***
case1
# 模板后面跟一个关键字,且用例主体部分是模板关键字的参数
# RF参数化的参数只能写死在用例文件中
[Template] api_test
参数1 参数2 参数3
参数A 参数B 参数C
log to console 执行不了 #会报错,因为对当作关键字api_test的参数
*** Keywords ***
api_test
[Arguments] ${args1} ${args2} ${args3}
log to console ${args1}
log to console ${args2}
log to console ${args3}
执行结果: