robotframework-ride使用(Builtin标准库
一、创建测试项目
1.1创建测试项目
选择菜单栏file-->new project

1.2.新建测试套件
右键点击测试项目选择new suite选项

1.3.创建测试用例
右键点击测试套件选择new Test Case

1.4从F5开始学习
RIDE提供了F5快捷键来打开帮助文档

Search term:用于搜索关键字
Source:用于选择相关库,默认在所有库下搜索关键字
创建分上下两部分,上半部分是关键字列表,下半部分显示某一关键字的详细说明。这些关键字的说明信息是由RIDE读取的代码函数(方法)的系统注释获得的
2.测试项目与测试套件的概念
测试项目是一个目录

测试套件是一个txt文档

除非我们所创建的测试项目非常小,只需要几个测试用例,一般情况下,我们会选择将其定义为一个目录,这样它就可以分成多个套件,套件可以定义为不同的业务,不同的业务下再分用例,结构会更加清晰。(即用例只能创建在file类型的文件中,不能是Directory类型的文件)
3.简单的demo
测试用例1:
robotframework中使用Open Browser关键字来操作浏览器驱动,Input Text关键字来输入文本值,
Click button关键字来点实现点击功能,sleep关键字实现休眠,单位秒,close Browser关键字来关闭浏览器。

测试用例2:使用变量
在robotframework中,通过使用Set variable关键字来定义变量如该用例

编辑完test case之后可以直接按下F8运行,或者run标签页中的start,同时在run标签页我们也将看到执行结果。


log.html

report.html

测试用例3:连接对象
使用Catenate关键字可以连接多个信息,加上“SEPARATOR=”可以对多个连接的信息进行分割。

执行过程:

测试用例4:定义列表
通过Create List关键字可以定义列表

执行过程如下:

每个字符串前面加u,是为了统一编码问题,将字符串转为Unicode编码。
测试用例5:@{}定义列表
如果通过@{}来定义列表,那么通过“log many”关键字进行打印

执行过程:

测试用例6:时间操作
robotframework中提供了“get time”关键字来获取当前时间

执行过程:

测试案例7:if语句
robotframework通过run keyword if关键字可以编写if分支

执行过程:

测试案例8:for循环
1)robotframework中提供了关键字":FOR"可以实现for循环

执行过程:

2)遍历列表

create list关键字用来定义列表{a,b,c},@{abc}用来存放列表,通过":for"循环遍历@{abc}列表中的字符
执行过程:

3)循环中的判断
robotframework中通过Exit For Loop If关键字来进行for循环内的判断,当满足Exit For Loop If条件后,循环结束

执行过程:

从执行过程中查看当循环到字符串c时,Exit For Loop If条件成立,结束循环,通过log打印当前的字符c
测试案例9:强大的Evaluate
为什么说Evaluate强大,因为通过它可以使用python语言中所提供的方法
1)生成随机数
python中生成随机整数我们可以这么写:

在robotframework中使用Evaluate也可以调用python所提供的random模块下的randint方法

执行过程:

2)执行本地程序(失败,未演示成功,找不到文件??)
通过调用python所提供的os模块中system()方法可以执行本地python文件,至于在.py文件python可以做任何想做的事情。
对于system()方法来说,它也不单单可执行python文件,任何在cmd命令提示符下可运行文件和命令,它都可以执行。
不过,一般情况下不建议通过sysetm()方法去执行外部程序。这样做其实是脱离了robotframework,也就是说不管robotframework什么事了。我们尽量把要做的事情通过python封装成关键字给robotframework使用。

4.注释
robotframework中添加注释也非常简单,“Comment”关键字用于设置脚本中的注释
同样也可以使用#来进行注释

本章节介绍的关键字全部由Builtin库提供,Builitin为robotframework提供标准库,Builtin库提供常用的关键字。
补充:如何定制robotframework的日志路径
在run的arguments输入这个“-l D:\RobotFramework\Robot_Report\log -r D:\RobotFramework\Robot_Report\report -o D:\RobotFramework\Robot_Report\output ”
