相信你已经迫不及待的要拿 Robot Framework 写自动化测试项目了,先别着急! 当你要使用 Python 去开发一个网站的时候,是不是要先从 Python 的基本语法学起? Builtin 库是 Robot Framework 自带的基础库,提供了一套基础的关键字。本节介绍的大多关键字都由该库提供。

log 就是 “print”


log 关键字就是编程语言里的 “print” 一样,可以打印任何你想打印的内容。


*** Test Cases ***

test case1
    log    robot framework
    log    python

定义变量


在 Robot Framework 中通过 “Set variable” 关键字来定义变量,如:


*** Test Cases ***

test case2
    ${a}    Set variable    python
    log    ${a}

连接对象


“Catenate”关键字可以连接多个对象


*** Test Cases ***

test case3
    ${hi}    Catenate    hello    world
    log    ${hi}

加上 “SEPARATOR=” 可以对多个连接的信息进行分割。


*** Test Cases ***

test case4
    ${hi}    Catenate    SEPARATOR=---    hello    world
    log    ${hi}

定义列表


如果通过 “@{}” 去定义列表的话,可以通过 “log many” 关键字进行打印


*** Test Cases ***

test case5
    @{abc}    Create List    a    b    c
    log many    @{abc}

时间操作


在 Robot Framework 中也提供操作时间的关键字。

1、 “get time” 关键字用来获取当前时间。


*** Test Cases ***

test case6
    ${t}    get time
    log    ${t}

2、 “sleep”关键字用来设置休眠一定时间


*** Test Cases ***

test case7
    ${t}    get time
    sleep    5
    ${t}    get time