常用关键字介绍

一、log(print)

# 输入代码 
log world

二、Set variable(定义变量)

Starting test: 测试项目.测试套件.test case
20191225 10:16:51.156 :  INFO : ${a} = hello world
20191225 10:16:51.157 :  INFO : hello world
Ending test:   测试项目.测试套件.test case

三、Catenate(连接对象)

3.1 Catenate

Starting test: 测试项目.测试套件.test case
20191225 10:16:51.156 :  INFO : ${a} = hello world
20191225 10:16:51.157 :  INFO : hello world
Ending test:   测试项目.测试套件.test case

3.2 SEPARATOR= 在连接中间进行信息分割

Starting test: 测试项目.测试套件.test case
20191225 10:25:52.710 :  INFO : ${a} = hello-----world
20191225 10:25:52.711 :  INFO : hello-----world
Ending test:   测试项目.测试套件.test case

四、Create List(创建列表)

4.1 $标识列表,输出用log

Starting test: 测试项目.测试套件.test case
20191225 10:35:24.499 :  INFO : ${abc} = ['a', 'b', 'c']
20191225 10:35:24.500 :  INFO : ['a', 'b', 'c']
Ending test:   测试项目.测试套件.test case

4.2 @标识列表,输出用log many

Starting test: 测试项目.测试套件.test case
20191225 10:38:09.237 :  INFO : @{abc} = [ a | b | c ]
20191225 10:38:09.239 :  INFO : a
20191225 10:38:09.239 :  INFO : b
20191225 10:38:09.239 :  INFO : c
Ending test:   测试项目.测试套件.test case

五、get time(时间的操作)

5.1 获取当前时间

Starting test: 测试项目.测试套件.test case
20191225 10:44:20.546 :  INFO : ${t} = 2019-12-25 10:44:20
20191225 10:44:20.546 :  INFO : 2019-12-25 10:44:20
Ending test:   测试项目.测试套件.test case

5.2 sleep 设置休眠一定时间

Starting test: 测试项目.测试套件.test case
20191225 10:48:36.553 :  INFO : ${t} = 2019-12-25 10:48:36
20191225 10:48:41.557 :  INFO : Slept 5 seconds
20191225 10:48:41.561 :  INFO : ${t} = 2019-12-25 10:48:41
Ending test:   测试项目.测试套件.test case

六、if语句

通过“run keyword if”关键字可以编写if 分支语句。

# 首先定义两个变量a 等于59 。
# If 判断a 大于等于90 ,满足条件log 输出“优秀”;
# 不满足上面的条件,接着else if 判断a 大于等于70 ,满足条件log 输出“良好”;
# 不满足上面的条件,接着else if 判断a 大于等于60 ,满足条件log 输出“及格”;
# 上面的条件都不满足,else log 输出“不及格”。
# 注:注意sele if 和else 前面的三个点点点(...)

Starting test: 测试项目.测试套件.test case
20191225 11:05:17.049 :  INFO : ${a} = 69
20191225 11:05:17.051 :  INFO : 及格
Ending test:   测试项目.测试套件.test case

七、:for循环

7.1 :for循环数字

Starting test: 测试项目.测试套件.test case
20191225 11:21:36.660 :  INFO : 0
20191225 11:21:36.660 :  INFO : 1
20191225 11:21:36.670 :  INFO : 2
Ending test:   测试项目.测试套件.test case

7.2 :for循环列表

Starting test: 测试项目.测试套件.test case
20191225 11:29:07.064 :  INFO : @{abc} = [ a | b | c ]
20191225 11:29:07.064 :  INFO : a
20191225 11:29:07.064 :  INFO : b
20191225 11:29:07.064 :  INFO : c
Ending test:   测试项目.测试套件.test case

7.3 :for循环中断

Starting test: 测试项目.测试套件.test case
20191225 13:02:01.079 :  INFO : @{abc} = [ a | b | c ]
20191225 13:02:01.081 :  INFO : a
20191225 13:02:01.081 :  INFO : b
20191225 13:02:01.082 :  INFO : Exiting for loop altogether.
Ending test:   测试项目.测试套件.test case

八、强大的Evsluate

通过evsluate可以使用Python 语言中所提供的方法

8.1 生成随机数

# 在Robot Framework 中使用“Evauate”也可以调用Python 所提供的random 模块下的randint()方法

Starting test: 测试项目.测试套件.test case
20191225 13:09:04.462 :  INFO : ${d} = 11
20191225 13:09:04.463 :  INFO : 11
Ending test:   测试项目.测试套件.test case

8.2 执行本地程序

# 通过调用Python 所提供的os模块中的system()方法可以执行本地Python 文件。至于在.py 文件中 Python 可以做任何想做的事

九、导入库

9.1 调用框架(import library)

9.1.1 正常调用已存在的库

# 在Robot Framework 中也提供了“Import Library”关键字来完成这个事情。如导入unittest,import library类似python中的import

9.1.2 导入不存在的库时

 

 

Starting test: 测试项目.测试套件.test case
20191225 13:27:45.092 :  FAIL : 
Importing test library 'HTMLTestRunner' failed: ModuleNotFoundError: No module named 'HTMLTestRunner'
Traceback (most recent call last):
  None
PYTHONPATH:
  D:\python36\Scripts\robot.exe
  d:\python36\python36.zip
  d:\python36\DLLs
  d:\python36\lib
  d:\python36
  d:\python36\lib\site-packages
  d:\python36\lib\site-packages\win32
  d:\python36\lib\site-packages\win32\lib
  d:\python36\lib\site-packages\Pythonwin
  d:\python36\lib\site-packages\robotide\contrib\testrunner\../../lib
Ending test:   测试项目.测试套件.test case
     
# Robot Framework 会遍历Python 安装目录下的相关目录查找“HTMLTestRunner”模块。

9.2 调用python文件

# test.py


def add(a, b): return a + b if __name__ == "__main__" a = add(4, 5) print a

Starting test: 测试项目.测试套件.test case
20191225 15:34:17.516 :  INFO : ${add} = 45
20191225 15:34:17.516 :  INFO : 45
Ending test:   测试项目.测试套件.test case

Starting test: 测试项目.测试套件.test case
20191225 15:37:08.361 :  INFO : ${a} = 4
20191225 15:37:08.362 :  INFO : ${b} = 5
20191225 15:37:08.362 :  INFO : ${add} = 9
20191225 15:37:08.363 :  INFO : 9
Ending test:   测试项目.测试套件.test case

posted on 2019-12-25 16:57  软饭攻城狮  阅读(324)  评论(0编辑  收藏  举报

导航