zoukankan      html  css  js  c++  java
  • RF之条件判断、初始化清除-4

    条件判断:

           rf中用run keyword if 关键字做条件判断,以此来达到类似在python中if ...else...条件判断的功能。

           注意:ELSE IF一定都是大写的,不然运行后会报错。

           RF中解决太长的问题:可以用下一行 前面加三个省略号,在测试用例中,下一行的省略号前面必须留一个以上的空单元格。

    *** Test Cases ***

    条件判断1

                    [Documentation]       run keyword if     需要注意的是:语法严格 in  左右只能一个空格  多了会报错

                    ${status}=                  set variable                abcd

                    run keyword if            'bc' in ${status}          log to console        bc包含在abcd里面

    条件判断2

                  [Documentation]      if  ...else...  分支

                  ${status}=                  set variable                abcde

                  run keyword if            'cd' in ${status}          log to console       cd包含在abcde里面

                  ...    ELSE                   log to console           cd没有包含在abcde里面      

    条件判断3

                  [Documentation]    if ...else if...else...   分支

                  ${'status'}=                  set variable                  rrrr

                  run keyword if             '${status}' == 'tttt'         log to console     1

                  ...     ELSE IF              '${status}' == 'rrrr'        log to console      2

                  ...     ELSE                   log to console              3

    else分支:在老版本的RF中,是没有else分支的,只能通过run keyword unless来达到目的。

                     run keyword unless和上面的run keyword if没有任何关系,可单独使用。

    条件判断4

                 [Documentation]     else分支   run keyword if unless

                 ${html}=     set variable        2019-12-02 UTC

                 run keyword if       '2019' in '$html and 'UTC' in $html

                 ...        log to console     是2019年的时间 UTC

                 run keyword if unless      '2017' in '$html and 'UTC' in $html

                 ...        log to console      不是2019年的时间 UTC

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    循环语句:

            RF中循环只有for循环

            Exit For Loop关键字实现break功能  ------- 完全结束循环

            用Continue For Loop实现continue 功能   -------- 终止本次循环

            也可以使用等价的关键字 Continue For Loop If    Exit For Loop If

    *** Test Cases ***

    循环里的判断1

                  ${weight}=     get value from user    请输入你的体重    60

                  log to console       体重为${weight}

                  run keyword if       int($weight)>60      log to console    太重了

                  ...      ELSE          log to console        太轻了    

    循环里的判断2

                  :for    ${one}    in range     99999

                        ${weight}=     get value from user     请输入你的体重    60

                        run keyword if     $weight=='over'       Exit For Loop  

                        run keyword if     $weight=='cont'       continue for loop

                        run keyword if     int($weight)>60        log to console      太重了

                          ...     ELSE        log to console          太轻了

    为了简洁简化,还可以这样写:

           exit for loop if                 $weight=='over'

           continue for loop if         $weight=='cont'

    evaluate的使用:

           evaluate关键字的参数为python的表达式,有的表达式需要引入模块,有的不需要模块默认不引入模块

           *** Test Cases ***

           ${var1}=       create list             hello,world

           ${var2}=       evaluate              'hello world'[:4]

           ${var3}=       evaluate               {'hello', 'world'}

           ${var4}=       evaluate               ['hello']*10

           ${var5}=       evaluate               math.fool(-2)         modules=math

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    初始化和清除:

           是测试一个用例之前要做的事情(setup)和测试后要做的事情(teardown)。

           在RF中,每个测试套件目录、测试套件文件、测试用例都可以有自己的setup的teardown。

           所有的setup和teardown操作都只能由一个关键字语句构成。

    初始化和清除写在测试用例表的配置项中:

           *** Test Cases ***

           test1

               [Documentation]        初始化和清除

               [Setup]             log to console            *******前置********

               log to console                  测试用例1主体部分

               [Teardown]      log to console             *******后置********

           test2

               [Documentation]       初始化和清除

               log to console                测试用例2主体部分

    测试套件文件的setup、teardown:

           写在测试套件文件的settings表中

           两种类型:   - Suite setup/teardown     进入和退出这个suite执行用例前后必须执行且只分别执行一次

                                - Test setup/teardown       如果suite内的用例本身没有setup/teardown, 才执行

           *** Settings ***

           Suite Setup       log to console        -----测试套件的前置------

           Suite Teardown      log to console        -------测试套件的后置--------

           Test Setup          log to console          -------前置--------

           Test Testdown      log to console        --------后置--------

    测试套件目录的setup、teardown:

           在其目录下的初始化文件__int__.txt 或者__init__.robot里的settings表中

           两种类型:   - Suite setup/teardown      进入和退出suite执行用例前后必须执行且分别执行一次

                                - Test setup/teardown        如果suite内的用例或者子套件  本身没有setup/teardown ,才执行

           *** Settings ***

           Suite Setup    log to console       -------测试套件的前置----------

           Suite Teardown    log to console         ---------测试套件的后置----------

           Test Setup        log to console       -----------前置----------

           Test Teardown     log to console        ---------后置----------

    目录下的文件执行方法:

            可以在终端,如:robot  suite1st1.robot

                   robot --suite st1 suite1

            如果只想执行文件中的某个具体的用例,怎么执行?

                   robot --test 测试1 suite1

  • 相关阅读:
    CSpinButtonCtrl控件的使用
    JS基础语法
    JS
    层级,hover
    Html&Css
    定位
    制作静态网页
    查看trunk端口
    配置vlan trunk
    js日期的写法,获取girdviw的行数、提示信息、验证数量信息
  • 原文地址:https://www.cnblogs.com/peipei-Study/p/12072739.html
Copyright © 2011-2022 走看看