RF-条件判断

条件判断

  • 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
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值