robot framework学习笔记之七—连接mysql数据库
1.安装Database-Library
输入命令:pip install robotframework_databaselibrary
2.添加Database的Library

3.实例
*** Test Cases ***
查询单条数据
${data} create dictionary shopCode=xxx coordinate=
${response} Rest.Get /api/shop/current.json ${data} form ${hosts["weidian"]}
Connect To Database Using Custom Params pymysql host='115.29.xx.xxx', port=3306, user='xx', passwd='xxx', db='test', charset= 'utf8'
${name} query select nickname from authshop where code='xxx'
log ${response["data"]["shop"]["shopName"]}
should be equal ${response['data']['shop']['shopName']} ${name[0][0]}
log ${name[0][0]} 查询多条数据 数据库中存在
#Check If Exists In Database
${data} create dictionary shopCode=xxx coordinate=
${response} Rest.Get /api/shop/current.json ${data} form ${hosts["weidian"]}
Connect To Database Using Custom Params pymysql host='115.29.xx.xx', port=3306, user='test', passwd='xxx', db='test', charset= 'utf8'
Check If Exists In Database select nickname from authshop where code='xxx' 数据库中不存在
#Check If Not Exists In Database
${data} create dictionary shopCode=xxx coordinate=
${response} Rest.Get /api/shop/current.json ${data} form ${hosts["weidian"]}
Connect To Database Using Custom Params pymysql host='115.29.xx.xxx', port=3306, user='xx', passwd='xx', db='test', charset= 'utf8'
Check If Exists In Database select nickname from authshop where code='xxx' 查询
#Description
${data} create dictionary shopCode=xxx coordinate=
${response} Rest.Get /api/shop/current.json ${data} form ${hosts["weidian"]}
Connect To Database Using Custom Params pymysql host='115.29.xx.xxx', port=3306, user='xxx', passwd='xxx', db='test', charset= 'utf8'
${qeeryResults} query select nickname from authshop where code='xxx'
log ${qeeryResults} 返回查询结果总行数
#Row Count
${data} create dictionary shopCode=xxx coordinate=
${response} Rest.Get /api/shop/current.json ${data} form ${hosts["weidian"]}
Connect To Database Using Custom Params pymysql host='115.29.xx.xxx', port=3306, user='xxx', passwd='xxx', db='xxx', charset= 'utf8'
${qeeryResults} row count select shop_code from authshop_relation where site_id=''
log ${qeeryResults}
4.api详情
| API | 参数 | 说明 |
| Check If Exists In Database | 查询语句 | 数据库中存在:存在,则为PASS,不存在,则为FAIL |
| Check If Not Exists In Database | 查询语句 | 数据库中不存在:不存在,则为PASS,存在,则为FAIL |
| Connect To Database | dbapiModuleName=None, dbName=None, dbUsername=None, dbPassword=None, dbHost=localhost, dbPort=5432, dbConfigFile=./resources/db.cfg | 连接数据库配制信息,通过配制各项属性完成 |
| Connect To Database Using Custom Params | dbapiModuleName=None, db_connect_string= | 连接数据库配制信息,通过db_connect_string来传递。如database='my_db_test', user='postgres', password='s3cr3t', host='tiger.foobar.com', port=5432 |
| Delete All Rows From Table | 表名 | 删除数据库中表的所有行:删除成功,则PASS;失败,则Fail |
| Description | 查询语句 | 返回查询语句的结果,内容格式为: [Column(name='id', type_code=1043, display_size=None, internal_size=255, precision=None, scale=None, null_ok=None)] [Column(name='first_name', type_code=1043, display_size=None, internal_size=255, precision=None, scale=None, null_ok=None)] [Column(name='last_name', type_code=1043, display_size=None, internal_size=255, precision=None, scale=None, null_ok=None)] |
| Disconnect From Database | 无 | 断开数据库链接 |
| Execute Sql Script | SqlScriptFileName | 执行脚本文件。SqlScriptFileName物理路径+FileName。 |
| Execute Sql String | SqlString | 执行Sql语句 |
| Query | 查询语句 | 返回查询语句的查询结果 |
| Row Count | 查询语句 | 返回查询语句的查询结果行总数 |
| Row Count Is 0 | 查询语句 | 查询语句的查询结果行总数:为0,则PASS;非0,则FAIL |
| Row Count Is Equal To X | 查询语句,X |
查询语句的查询结果行总数:为X,则PASS;非X,则FAIL X,为预期的查询结果行数,第二个需要传递的参数 |
| Row Count Is Greater Than X | 查询语句,X |
查询语句的查询结果行总数:大于X,则PASS;小于或等于X,则FAIL X,为预期的查询结果行数,第二个需要传递的参数 |
| Row Count Is Less Than X | 查询语句,X |
查询语句的查询结果行总数:大于X,则PASS;小于或等于X,则FAIL X,为预期的查询结果行数,第二个需要传递的参数 |
| Table Must Exist | 表名 | 表名必须存在:存在,则PASS;不存在,则FAIL |
5.实例二
#Connect To Database Using Custom Params:使用参数来连接数据库 pymysql:连接的数据库 charset=‘utf8’解决中文显示成???的问题
Connect To Database Using Custom Params pymysql host=‘115.29.10.xxx’, port=3306, user=‘xxx’, passwd=‘xxx’, db=‘xxx’,charset=‘utf8’
#使用Query方法来执行"select name from wx_account_detail where type=0”,并将查询的结果返回对变量@{name}
@{name} query select name from wx_account_detail where type=0
#循环获取多条记录的值,并打印
: FOR ${i} IN RANGE 0 len(@{name})
\ log @{name}[${i}]

robot framework学习笔记之七—连接mysql数据库的更多相关文章
- openresty 学习笔记四:连接mysql和进行相关操作
openresty 学习笔记四:连接mysql和进行相关操作 毕竟redis是作为缓存,供程序的快速读写,虽然reidis也可以做持久化保存,但还是需要一个做数据存储的数据库.比如首次查询数据在red ...
- MySQL学习(一)——Java连接MySql数据库
MySQL学习(一)——Java连接MySql数据库 API详解: 获得语句执行 String sql = "Insert into category(cid, cname) values( ...
- robot framework学习笔记2
声明:本笔记都只是自己根据大牛虫师的robot系列文档学习记录的,学习的话还请移步虫师博客:https://www.cnblogs.com/fnng/ 非常感谢大牛的分享,带小白一步一步入门 F5 ...
- django学习-10.django连接mysql数据库和创建数据表
1.django模型 Django对各种数据库提供了很好的支持,包括:PostgreSQL.MySQL.SQLite.Oracle. Django为这些数据库提供了统一的调用API. 我们可以根据自己 ...
- Robot Framework学习笔记(三)------常用关键字介绍
下面关键字全部由 Builtin 库提供,Builtin 为 Robot Framework 标准类库.Builtin库提供常用的关键字 1.log log 关键字就是编程语言里的"prin ...
- python学习笔记之——操作mysql数据库
Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: ...
- robot framework学习笔记之二———变量
Robot Framework的变量分为标量, 列表和字典, 分别使用语法格式 ${SCALAR}, @{LIST} 和 &{DICT} 来定义. 此外, 环境变量可以直接使用语法 %{ENV ...
- Python学习笔记9-Python 链接MySql数据库
Python 链接MySql数据库,方法很简单: 首先需要先 安装一个MySql链接插件:MySQL-python-1.2.3.win-amd64-py2.7.exe 下载地址:http://dev. ...
- Robot Framework学习笔记(十一)------ 分层设计
以百度搜索为例,如果我们需要写5个不同关键字搜索的用例.如果没有分层的思想,那么我们需要写5个用例,并且每个用例都需要重复写打开浏览器.输入关键字.点击按钮.关闭浏览器的步骤.如果使用Robot Fr ...
随机推荐
- UNITY Destroy()和DestroyImadiate()的区别
using System.Collections; using System.Collections.Generic; using System.Timers; using UnityEngine; ...
- SpinBlur - 旋转模糊
[SpinBlur - 旋转模糊] Using the Spin Blur effect, you can rotate and blur the image around one or more p ...
- Ice_cream’s world II(最小树形图,加虚点)
Ice_cream’s world II http://acm.hdu.edu.cn/showproblem.php?pid=2121 Time Limit: 3000/1000 MS (Java/O ...
- 265. Paint House II 房子涂色K种选择的版本
[抄题]: There are a row of n houses, each house can be painted with one of the k colors. The cost of p ...
- Python:如何排序(sort)
一.前言 对Python的列表(list)有两个用于排序的方法: 一个是内建方法list.sort(),可以直接改变列表的内容: >>> list1 = [9,8,7,6,5] &g ...
- linux 关键发行版及其关系图
- Solr分词搜索结果不准确
Solr的schema.xml默认配置分词后条件取 OR 例如:大众1.6T 系统会自动分词为 [大众] [1.6T](ps:不同分词器分词效果不同) 会搜索出包含 [大众 OR 1.6T] ...
- ps 中添加一张图片
// 测试打开一个文件var fileref = new File ("/E/work/没有图片提交/2014/2014.5.19/G20/部件渲染测试/png/tianji_1-41001 ...
- FZU 1977 Pandora adventure (DP)
题意:给定一个图,X表示不能走,O表示必须要走,*表示可走可不走,问你多少种走的法,使得形成一个回路. 析: 代码如下: #pragma comment(linker, "/STACK:10 ...
- (DP)uva 10036 Problem C: Divisibility
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88171#problem/F 代码: #include <cstdio> ...