Robot Framework:数据库操作

robotframework 操作数据库,需要安装DatabaseLibrary库

pip install robotframework-databaselibrary

Python操作不同的数据库,需要安装对应的数据库驱动。

pip install cx_Oracle    # Oracle驱动,支持9.210.211.1等版本

pip install PyMySQL     # MySQL驱动

 将DatabaseLibrary 导入robotframework

   Oracle                                                                              

将Oracle安装目录下的文件,复制到site-packages目录中

使用方法 connect to database using custom params | cx_Oracle | 'username','password','172.24.5.12:1521/test02'

 

   MySQL                                                                             

 

 链接数据库关键字,使用方法 connect to database using custom params cx_Oracle | 'username','password','172.24.5.12:1521/test02'

 

遇见问题:

数据库查询中文结果为Unicode编码。('\xe5\x86\x85\xe7\xa7\x91',)

解决方案:在DatabaseLibrary下的query.py文件中,添加

    def decode(self,code):
        return code.decode('utf-8')

然后在使用的时候,如下图:

 

posted on 2018-12-05 16:09  rechin  阅读(774)  评论(0编辑  收藏  举报

导航