RF--基础

常用关键字:

${var}  set variable  hello world  #${var}为变量的常用书写格式,set variable设置变量,均为字符串

${var2}  set variable  hello world  #${var}为变量的常用书写格式,set variable设置变量,均为字符串

log to console  ${var}  #会输出到控制台

log  ${var}  #不会输出到控制台,会输出到日志里

sleep  1  #默认单位为秒s,可以设置其他单位1d,2h,3m,4s,5ms,例sleep 5ms

should be equal  ${var}  hello world  #判断

should contian  ${var}  hello  #断言${var}中是否包含hello

should be true  'hello word'==$var  #这里把  'hello word'==$var  看成一个字符串表达式,当${var}为字符串时,在should be true调用时会省去引号

should be true注释:

*** Test Cases ***
case1:
    ${var}  set variable  hells
    should be true  hello == ${var}
结果:FAIL
Evaluating expression 'hello == hells' failed: NameError: name 'hello' is not defined
此次报错信息为hello未定义,在python中字符串hello应写为'hello'

case2把hello改为'hello',此处变量依旧用hells是为了体现是变量错误
*** Test Cases ***
case2:
    ${var}  set variable  hells
    should be true  'hello' == ${var}
结果:FAIL
Evaluating expression ''hello' == hells' failed: NameError: name 'hells' is not defined
报错信息为'hells'未定义,在rf中的should be true比较中,调用字符串变量时,直接取引号''内部的数据

*** Test Cases ***
case3:
    ${var}  set variable  hello
    should be true  'hello' == '${var}'
结果:PASS
直接在调用的字符串变量外部加引号来弥补本身调用的问题

*** Test Cases ***
case4:
    ${var}  set variable  hello
    should be true  'hello' == $var
结果:PASS
另一种书写方式,在should be true中, 加引号'${var}'和去大括号$var代表的意思相同

*** Test Cases ***
case5:
    ${var}  set variable  [1,2]
    should be true  '[1,2]' == $var
结果:PASS
在遇到变量不是字符串格式时,依旧如同case4的格式书写

 

posted @ 2020-07-06 23:43  追逐蹉跎的岁月  阅读(392)  评论(0编辑  收藏  举报