RF之条件判断、初始化清除-4

条件判断:html

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

       注意:ELSE IF必定都是大写的,否则运行后会报错。less

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

*** Test Cases ***测试

条件判断1ui

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

                ${status}=                  set variable                abcdhtm

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

条件判断2it

              [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  suite1\st1.robot

               robot --suite st1 suite1

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

               robot --test 测试1 suite1

相关文章
相关标签/搜索