条件判断:

       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

RF之条件判断、初始化清除-4的更多相关文章

  1. rf中的条件判断与循环

    条件判断 run keyword if condition name *args ... ELSE IF conditon name *args ...ELSE name *args conditio ...

  2. Linux centosVMware 自动化运维Ansible介绍、Ansible安装、远程执行命令、拷贝文件或者目录、远程执行脚本、管理任务计划、安装rpm包/管理服务、 playbook的使用、 playbook中的循环、 playbook中的条件判断、 playbook中的handlers、playbook实战-nginx安装、管理配置文件

    一.Ansible介绍 不需要安装客户端,通过sshd去通信 基于模块工作,模块可以由任何语言开发 不仅支持命令行使用模块,也支持编写yaml格式的playbook,易于编写和阅读 安装十分简单,ce ...

  3. shell条件判断与流程控制

    一 条件判断式语句 1.按文件类型进行判断 测试类型 作用 -b 文件 判断文件是否存在,并且是否为块设备文件(是块设备文件为真) -c 文件 判断文件是否存在,并且是否为字符设备文件(是字符设备设备 ...

  4. Bash条件判断

    bash编程之:条件判断,判定后续操作的前提条件是否满足, bash编程之: 条件判断常用类型: 整数测试:比较两个整数谁大谁小,是否相等: 二元测试: num1 操作符 num2 -eq: 等于 - ...

  5. bash脚本编程之二 条件判断and 逻辑运算

    1.条件测试结构 1) if/then结构: 判断命令列表的退出码是否为0,0为成功. 如果if和then在条件判断的同一行上的话, 必须使用分号来结束if表达式: if和then都是关键字. 关键字 ...

  6. [Shell]条件判断与流程控制:if, case, for, while, until

    ---------------------------------------------------------------------------------------------------- ...

  7. Linuxshell脚本之if条件判断

    IF条件判断 .基本语法: if [ command ]; then 符合该条件执行的语句 fi .扩展语法: if [ command ];then 符合该条件执行的语句 elif [ comman ...

  8. 老李分享:Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1 - 条件判断法

    老李分享:Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1 - 条件判断法   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜 ...

  9. [译] NSScanner:一个陌生的条件判断利器!

    NSScanner官方文档 NSScanner类是一个类簇的抽象父类,该类簇为一个从NSString对象扫描值的对象提供了程序接口. NSScanner对象把NSString 对象的的字符解释和转化成 ...

随机推荐

  1. cf 911F 树的直径+贪心

    $des$ 给定一棵 n 个节点的树,你可以进行 n ? 1 次操作,每次操作步骤如下:选择 u,v 两个度数为 1 的节点.将 u,v 之间的距离加到 ans 上.将 u 从树上删除.求一个操作序列 ...

  2. (14)打鸡儿教你Vue.js

    重构 "代码重构" 为什么要进行重构 提高代码的可读性和可维护性 代码中存在着重复的代码 存在过大的类或过长的方法 强依赖.紧耦合的结构 运算逻辑难以理解 代码不能清晰 统一的编码 ...

  3. Pytest权威教程08-使用tmp目录和文件

    目录 使用tmp目录和文件 tmp_path Fixture方法 tmp_path_factory Fixture方法 tmpdir Fixture方法 tmpdir_factory Fixture方 ...

  4. Ubuntu16.04 RYU pip命令安装

    pip命令安装方法 sudo apt install gcc python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev ...

  5. MITMProxy如何配置二次代理

    MITMProxy如何配置二次代理 0.2172018.09.05 11:13:15字数 232阅读 2609 前序: mitmproxy真的很强大,或许是大家都各自使用,或者没有相关的需求,导致我废 ...

  6. 范仁义html+css课程---1、html基本结构

    范仁义html+css课程---1.html基本结构 一.总结 一句话总结: html标签中包含head标签和body标签,head标签里面主要写用户不可见的内容,比如字符集编码,body标签里面主要 ...

  7. Go 随机打乱 字符串 数组

    func Random(strings []string) string { for i := len(strings) - 1; i > 0; i-- { num := rand.Intn(i ...

  8. css3的选择器有哪几种?

    *通用选择器,ID选择器 ,.类选择器class,标签选择器,标签组合选择器,伪类选择器:,+相邻元素选择器,>子元素选择器,~同辈选择器,x[title]属性选择器[type="bu ...

  9. 使用adb 命令(atrace)抓起systrace的方法。【转】

    本文转载自:https://www.cnblogs.com/liuliu-word/p/9963017.html adb shell atrace -c -b 10240 --async_start ...

  10. VS2010专业版和旗舰版(中文版)下载

    本文转载自https://blog.csdn.net/chy2z/article/details/80080399 注意: 中文版为iso镜像文件,使用 Daemon Tools 虚拟光驱软件载入进行 ...