Robot Framework 教程 (5) - 连接Oracel数据库
来源:互联网 发布:淘宝上买黄牛票犯法吗 编辑:程序博客网 时间:2024/05/23 00:43
1.安装Database Library
打开Robot Framework官网,找到Database Library,官网提供了Java 和Python两个版本的Database Library,这里我使用的是Python版,地址为
http://franz-see.github.io/Robotframework-Database-Library/
其中的软件Requirement一节是Database Library的运行环境需求,具体需求包括
Python/Jython/IronPython
Robotframework
A Database API Specification 2.0 Python Module that you will use to connect to the database.
其中的Python与Robot Framework我们已经安装过,现在需要安装一个Database API Specification 2.0 Python Module,也就是用于连接数据库的Python模块。
这里的逻辑是这个样子的,Database Library实际上是一个处在Robot Framework和Database Interfaces 中间的代理模块,Robot Framework 通过Database Library 所提供的接口,间接的调用Database Interfaces,从而实现操作数据库的目的。
打开Database Interfaces页面,找到Oracle的API驱动及下载地址,找到你对目前python环境对应版本的安装文件,下载安装
http://sourceforge.net/projects/cx-oracle/files/
之后,下载安装DatabaseLibrary。
安装完成后,在你的 \Python27\Lib\site-packages目录下,可以看到Database Library文件夹和cx_Oracle.pyd文件
2.编写测试脚本
运行RIDE,按F5查看Database Library的关键字。
我们编写一个数据库查询的测试用例,脚本如下:
Connect To Database Using Custom Params cx_Oracle 'bpm','bpm','orcl'@{data} query select * from sys_userlog many @{data}log ${data[0][1]}${count} Get length ${data}log ${count}Disconnect From Database
运行脚本,结果如下
运行后查看Log,表中的中文全部变成了乱码。cx_Oracle的默认编码不是Utf-8,需要人工转换一下。DataBaseLibrary自身没有提供转换函数,为了解决这个问题,我们需要对DataBaseLibrary进行扩展。
3.解决Database Library中文乱码问题
打开安装目录下的 query.py文件,添加一个decode函数,用于对字符串进行解码
def decode(self,customstr,mode): return customstr.decode(mode)
更改测试脚本,增加转码过程
再次运行,得到系统输出,测试通过
总结:
至此,完成了Robot Framework连接数据库并进行操作的过程。具体在使用过程中,还需要针对业务逻辑设计TestCase、编写sql来实现。
下一篇文章,我们将会对Robot Framework在编写测试脚本时,如何使用IF条件表达式做过程控制做说明。
- Robot Framework 教程 (5) - 连接Oracel数据库
- Robot Framework 教程 - 连接Oracel数据库
- Robot Framework - 连接Oracel数据库
- robot framework 连接数据库
- Robot Framework - 连接mysql数据库
- Oracel连接数据库
- PHP连接oracel数据库
- Robot Framework 教程 - 概述
- Robot Framework中使用DatabaseLibrary来连接数据库(SQLServer+MySQL)
- Robot Framework中使用DatabaseLibrary来连接数据库(MySQL)
- Robot Framework连接Oracle数据库(汇总自网络)
- Robot Framework-DatabaseLibrary数据库(MySql)
- Robot Framework-DatabaseLibrary数据库(MySql)
- Robot连接sqlserver数据库
- 解决Robot Framework 使用cx_Oracle连接Oracle数据库中文不识别的问题
- Robot Framework中使用AtuoItLibrary教程
- Robot Framework 教程 (2) - 页面元素定位
- Robot Framework 教程 (4) - 自定义Library
- mysql修改数据库表和表中的字段的编码格式的修改
- Robot Framework 教程 (2) - 页面元素定位
- Robot Framework 教程 (3) - Resource及关键字 的使用
- (八) Freemarker 总结
- Robot Framework 教程 (4) - 自定义Library
- Robot Framework 教程 (5) - 连接Oracel数据库
- App架构设计经验谈:业务层的设计
- Robot Framework 教程 (6) - 使用条件表达式
- Robot Framework 教程 (7) - 使用For循环
- 多层ViewGroup性能
- nginx + tomcat 集群实现负载均衡
- JMeter性能测试基础 (1) - 安装及简单使用
- JMeter性能测试基础 (2) - 变量的使用
- JMeter性能测试基础 (3) - 使用参数文件做搜索引擎性能对比