Robot Framework基础关键字


1、Builtin库

  • Robot Framework基础关键字封装在Builtin库中,库中包含了最基础的一些关键字
  • 如:打印、定义变量、定义数组、时间、分支语句、循环语句、调用Python模块… …
  • Robot Framework默认加载Builtin库

2、其它基础库

  • 其它基础库:Dialogs、Collections、OperatingSystem、Remote、Screenshot、String、Telnet、XML、Process、DateTime
  • Robot Framework默认不加载这些库,需要时可手动加载

3、基础关键字

3.1、log

  • 【作用:】打印
    在这里插入图片描述
*** Test Cases ***
Log
    log    Hello world!

3.2、Set variable

  • 【作用:】定义变量
    在这里插入图片描述
*** Test Cases ***
Set variable
    ${a}    Set variable    Hello world!
    log    ${a}

3.3、Create List

在这里插入图片描述

*** Test Cases ***
Create List
    ${abc}    Create List    a    b    c
    log    ${abc}
    log    ${abc}[0]

输出:
[‘a’, ‘b’, ‘c’]
a

3.4、Catenate

在这里插入图片描述

*** Test Cases ***
Catenate
    ${hi}    Catenate    Hello    world    !
    log    ${hi}
    ${hi}    Catenate    SEPARATOR=_    Hello    world
    log    ${hi}
    ${hi}    Catenate    SEPARATOR=    Hello    world
    log    ${hi}

输出:
Hello world !
Hello_world
Helloworld

3.5、get time

在这里插入图片描述

*** Test Cases ***
get time
    ${t}    Get time
    log    ${t}
    ${t}    Get Time    epoch    #时间戳,1970-01-01 00:00:00 UTC)之后以秒为单位返回时间
    log    ${t}
    ${t}    Get Time    return year    #返回年
    log    ${t}
    ${t}    Get Time    year,month,day    #返回年、月、日
    log    ${t}
    @{t}    Get Time    year month day hour min sec    #年、月、日、时、分、秒
    log    ${t}
    ${s}    ${y}    Get Time    seconds and year    #秒和年分别赋给${s}和${y}
    log    ${s}
    log    ${y}

输出:
2019-10-13 12:25:031570940703

3.6、if

在这里插入图片描述

*** Test Cases ***
if
    ${a}    Set variable    59
    run keyword if    ${a} >=90    log    优秀
    ...    ELSE IF    ${a} >=60    log    及格
    ...    ELSE    log    不及格

3.7、for

3.7.1、:For

在这里插入图片描述

*** Test Cases ***
for
    : FOR    ${i}    IN RANGE    5
    \    log    ${i}

输出:
0
1
2
3
4

3.7.2、Exit For Loop

  • 【作用:】满足条件时,跳出循环,后面的循环不再执行
  • 与 Exit For Loop If 功能一致
    在这里插入图片描述
*** Test Cases ***
Exit For Loop
    :FOR    ${i}    IN RANGE    5
    \    log    ${i}
    \    Run Keyword If    ${i}==2    Exit For Loop
    \    log    第${i}

输出:
0
第0次
1
第1次
2
Exiting for loop altogether.

3.7.3、Exit For Loop If

  • 【作用:】满足条件时,跳出循环,后面的循环不再执行
  • 与 Exit For Loop 功能一致
    在这里插入图片描述
*** Test Cases ***
Exit For Loop If
    :FOR    ${i}    IN RANGE    5
    \    log    ${i}
    \    Run Keyword If    ${i}==2    Exit For Loop
    \    log    第${i}

输出:
0
第0次
1
第1次
2
Exiting for loop altogether.

3.7.3、Continue For Loop

  • 【作用:】满足条件时,跳出本次循环,继续执行后面的循环
  • 与 Continue For Loop If 功能一致
    在这里插入图片描述
*** Test Cases ***
Continue For Loop
    :FOR    ${i}    IN RANGE    5
    \    log    ${i}
    \    Run Keyword If    ${i}==2    Continue For Loop
    \    log    第${i}

输出:
0
第0次
1
第1次
2
Continuing for loop from the next iteration.
3
第3次
4
第4次

3.7.4、Continue For Loop If

  • 【作用:】满足条件时,跳出本次循环,继续执行后面的循环
  • 与 Continue For Loop 功能一致
    在这里插入图片描述
*** Test Cases ***
Exit For Loop If
    :FOR    ${i}    IN RANGE    5
    \    log    ${i}
    \    Continue For Loop If    ${i}==2
    \    log    第${i}

输出:
0
第0次
1
第1次
2
Continuing for loop from the next iteration.
3
第3次
4
第4次

3.8、Evaluate

在这里插入图片描述

Evaluate
    ${d}    Evaluate    random.randint(10,20)    random    #调用python的random模块下的randint()函数
    log    ${d}
    ${t}    Evaluate    time.time()    time    #调用python的time模块下的time()函数
    log    ${t}

输出:
10
1570943550.7417426

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值