Robot Framework常用关键字

虽然通过RIDE提供“填表”一样的写测试用例的方式。但它却支持强大的关键字功能,以及可以开发关键字的扩展能力。

Comment

注释功能,也可以使用python中的"#"

Comment 注释
#注释

log

打印。类似于print

log Hello World

set variable

定义变量

$ set variable Hello World!!!
log $

catenate

连接对象

$ catenate hello world
log $

SEPARATOR

对多个连接进行分割(必须大写)

$ catenate SEPARATOR=, hello world
log $

create list

创建列表

$ create list a b c
log $

通过@{}定义列表

必须使用 log many 打印

@ create list a b c
log many @

get time

获取当前时间

$ get time
log $

sleep

设置休眠时间

$ get time
sleep 5
$ get time

run keyword if

通过该语句可以编写if分支语句

$ set variable 59
run keyword if ${a}>=90 log 优秀
... ELSE IF ${a}>=60 and ${a}<90 log 一般
... ELSE log

:FOR

实现循环

:FOR $ IN RANGE 10
log $

列表遍历

@ create list a b c
:FOR $ in @
log $

Exit For Loop If

退出循环的判断语句

@ create list a b c
:FOR $ IN @
exit for loop if '${a}'=='b'
log $

Evaluate

执行python中的方法

$ Evaluate random.randint(1000,9999) random
log $

Import Library

导入标准和第三方模块或框架。比如调用unittest单元测试框架

Import Library unittest

导入外部py文件

Import Library c:/test.py
$ add 3 4
log $
Import Library c:/test.py
$ Evaluate int(4)
$ Evaluate int(5)
${sum} | add | $ $
log $

Take Screenshot

截取当前屏幕,Screenshot库为robot framework的标准类库,需手动加载

字典

Collections库:该库为Robot Framework标准类库,它提供的关键字主要用于列表、索引、字典的处理。需要手动加载。

Create Dictionary

创建字典

$ Create Dictionary sname Luffy age 19

Get Dictionary Items

获取字典中的key和value

| ${item} | Get Dictionary Items | ${dict} |
| log | ${item} ||

Get Dictionary Keys

获取字典中的key

$ Get Dictionary keys $
log $

Get Dictionary Values

获取字典中的value

$ Get Dictionary Values $
log $

Get From Dictionary

根据key获取对应的value

$ Get From Dictionary $ sname
log $
posted @ 2019-12-20 04:00  心脏鼓点  阅读(2513)  评论(0编辑  收藏  举报