条件判断:

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

robot --suite st1 suite1

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

robot --test 测试1 suite1

最新文章

  1. mysql 安装以及运行
  2. (二)cordova+framework7入门——笑笑APP
  3. noip模拟赛(10.4) 序列(sequence)
  4. asp.net生产环境和开发环境的错误日志包装策略
  5. H5+CSS3实现手指滑动切换图片
  6. 最短路算法floyd
  7. Entity Framework中的Migration问题
  8. MBProgressHUD的基本使用
  9. Android中目的地Intent的使用
  10. JavaScript检测提交表单text合法
  11. window.open打开新窗体并用post方式传参
  12. JS-JAVASCRIPT的eval()方法
  13. Entity Framework 学习总结之十一:POCO
  14. 004_为什么不推荐APP使用SSL-PINNING
  15. 使用freemarker对模板进行渲染
  16. .NetCore下使用Prometheus实现系统监控和警报 (五)进阶自定义收集指标 之 Counter
  17. 【IDEA】【4】遇到的问题
  18. DS哈希查找--线性探测再散列
  19. vue2.0 中#$emit,$on的使用详解
  20. Android 2018最新的三方库

热门文章

  1. 看加载的php.ini 和 phpinfo 配置路径
  2. c语言实现杨辉三角形
  3. Pytest权威教程12-跳过(Skip)及预期失败(xFail): 处理不能成功的测试用例
  4. 启动tomcat闪退
  5. Tkinter 之TreeView表格与树状标签
  6. lol英雄时刻
  7. Skpi List跳表
  8. tail -f 加过滤功能
  9. JVM 主动类和被动类的使用
  10. 部署gerrit环境完整记录【转】