条件判断:

       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. ServletContext对象应用——三天免登录

    1.用到的知识点: (1)Cookie (2)Session (3)ServletContext 其中Cookie和Session是会话技术的组成部分,一次会话从打开浏览器的某个站点开始,到浏览器关闭 ...

  2. python模块之psutil

    一.模块安装 1.简介 psutil是一个跨平台库(http://pythonhosted.org/psutil/)能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息. ...

  3. shell命令的原理

    https://blog.csdn.net/m0_37925202/article/details/80258974 https://blog.csdn.net/a15929748502/articl ...

  4. github上项目的目录结构说明

    build 构建脚本 dist 编译出来的发布版 docs 文档 examples 示例文件 src 源码 test 测试脚本 .babelrc Babel 交叉编译的配置 .eslintrc ESL ...

  5. 数据结构实验之排序二:交换排序 (SDUT 3399)

    #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; ...

  6. 《挑战30天C++入门极限》C++类的继承与多重继承的访问控制

        C++类的继承与多重继承的访问控制 在前面的练习中我们一直在使用public的继承方式,即共有继承方式,对于protected和private继承方式,即保护继承与私有继承方式我们并没有讨论. ...

  7. [SDOI2009][BZOJ 1226]学校食堂

    Description 小F 的学校在城市的一个偏僻角落,所有学生都只好在学校吃饭.学校有一个食堂,虽然简陋,但食堂大厨总能做出让同学们满意的菜肴.当然,不同的人口味也不一定相同,但每个人的口味都可以 ...

  8. Java GUI小程序--画板

     画板效果  (以前写在Csdn上的博文,没去水印,Csdn名字同博客园) 布局类: package gary; import java.awt.Color; import java.awt.even ...

  9. archlinux安装nvidia-1050ti闭源驱动教程,亲测

    link:https://blog.csdn.net/u014025444/article/details/91454059

  10. 普通的checkbox的回显功能

     var ypxt=document.getElementsByName("map.LCSYLB");           var jgjg='${map.LCSYLB}';    ...