自动化测试框架RF---条件判断run keyword if

条件判断run keyword if

(1)结构:

         run keyword if     conditions(python表达式)     代码块   

         ELSE IF    conditions(python表达式)     代码块

         ELSE    代码块

 如下代码示例:

*** Test Cases ***
条件判断1
    ${time_now}     get time
    log to console  ${time_now}
    # run keyword if    contions(python条件表达式)
    run keyword if  '22' in $time_now
    ...     log to console  十点了,该睡觉了
    ...     ELSE IF    '23' in $time_now
    ...     log to console  十一点钟啊,赶紧睡觉
    ...     ELSE    log to console  起来嗨

运行结果:

(2)结合FOR循环使用

  代码示例:

条件判断+for循环
    # 遍历0-9,打印出其中的奇数,遇到8,退出循环
    FOR     ${item}     IN RANGE    10
        run keyword if  $item%2==1
        ...     log to console  ${item}
        ...     ELSE IF     $item==8  exit for loop
    END

运行结果:

猜你喜欢

转载自blog.csdn.net/qq_19982677/article/details/108654512