手把手教你学robotframework自动化框架(第一章:环境
目录
8、如何自己编写一个library(2021年1月28日完成)
9、数据库连接
9、如何支持win32应用
10、接口测试
11、持续集成
12、自定义包
13、ride使用(快捷键、tear down、timeout、template、tags)
14、常见问题
1、环境配置
1.1 python 环境配置
16年搭建robotframework时使用的是python2,但是现在看到官网说明python2后期不再维护了,所以我配置的python版本是:3.7.5。
下载地址:https://www.python.org/downloads/release/python-375/
安装:python下载后可以直接安装
环境变量配置:我是将python安装在了D盘,配置环境变量如下图

1.2 pip安装
1.2.1 什么是pip
pip 是 Python 包管理工具。提供了对 Python 包的查找、下载、安装、卸载的功能。
如:$ pip install requests 就是直接在本机安装requests的python包。
$ pip uninstall requests 是在本地卸载requests的python包。
1.2.2 为什么安装pip
如果不用pip,我们需要先下载所需要的python包,然后再本地执行python setup.py install的指令才能安装python的包。但是如果安装了pip,可以直接用pip指令下载和安装所需要的包。
1.2.3 如何安装pip
python3已经自带了pip,所以不需要单独在安装pip。可以在python的安装路径下面,比如我的是D:\Python38\Lib\site-packages 下面看到pip的包。
1.3 安装wxpython
1.3.1 什么是wxpython
wxPython 是 Python 语言的一套优秀的 GUI 图形库,因为我们要使用ride来编写自动化用例,ride是图形化工具,所以需要有wxpython的支持。
1.3.2 安装
版本:4.1.1(最新版本)
下载地址:https://pypi.org/project/wxPython/4.1.1/
使用pip安装,指令:pip install wxPython==4.1.1,截图如下:

1.4 安装robotframework
比较简单,使用pip指令安装即可。
pip install robotframework
1.5 安装ride
1.5.1 什么是ride
RIDE是一款专门用来编辑Robot Framework用例的软件,用Python编写并且开源。
1.5.2 如何安装
pip安装,指令:pip install robotframework-ride
1.5.3 如何打开
因为用例是用ride编写,所以安装后可以在桌面看到一个ride的图标,双击后启动

双击后打开如下

1.6 安装selenium2library
1.6.1 什么是selenium2library
封装了web页面实现ui自动化的指令,包含了点击、输入等常用的事件。直接调用即可。
1.6.2 安装
pip install selenium2library
安装成功后,可以在python的安装目录下看到

基础环境配置完毕!
2、一个简单的实例
2.1 ride如何创建一个用例
1)先创建一个项目,我的项目名称设置为test。注意,type要选择Directory。

2)项目下再新增一个suite,suite表示测试用例集


3)在suite下新增测试用例。


4)编写测试用例的步骤
以最简单的打开百度首页为例。
1)需要先引用selenium2library包,前面安装的时候我们说过,这个里面包含了模拟web测试的事件。
在suite级别进行引用。suite下的所有用例就可以使用了。点击suite的settings-》Library

2)按下键盘的F5,可以查阅selenium2library里面包含的可用关键字

3)使用关键字
比如我们要打开百度,首先需要打开浏览器,进入www.baidu.com这个url,查看关键后我们了解到可以使用open browser这个关键字。
通过阅读关键字的定义、解释和示例。我们可以模仿使用。
4)编写用例

具体打开浏览器用例步骤如下

5)执行用例。执行用例时execution profile一般可以选择pybo(就不用配置script to run tests),如果选择后不能使用,也可以参考我下面这个图的配置来执行。

6)查看执行日志,点击report和log都可以查询日志。




至此,一个最基本的自动化测试用例就完成了!