常用关键字介绍
一、log(print)
# 输入代码 log world
二、
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
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
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
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
五、
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
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循环
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
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
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
# 在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
# 通过调用Python 所提供的os模块中的system()方法可以执行本地Python 文件。至于在.py 文件中 Python 可以做任何想做的事
九、导入库
# 在Robot Framework 中也提供了“Import Library”关键字来完成这个事情。如导入unittest,import library类似python中的import
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”模块。
# test.py
def add(a, b): return a + b if __name__ == "__main__" a = add(4, 5) print aStarting test: 测试项目.测试套件.test case 20191225 15:34:17.516 : INFO : ${add} = 45 20191225 15:34:17.516 : INFO : 45 Ending test: 测试项目.测试套件.test caseStarting 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