robotframework - database操作(增删改查)
阅读原文时间:2023年07月08日阅读:8

1、前置配置条件准备

  a、mysql环境配置ok

  b、robot环境配置ok

  c、pip 安装robotframework-databaselibrary

2、mysql数据操作 -->以操作 test 数据库中的 student 为例

3、打开ride,进入robot页面

  pip install robotframework-databaselibrary

a、执行insert 插入语句后查看数据库是否插入成功数据;

b、执行select语句;

c、执行update语句后查看数据库是否有更新;

4、执行delete语句后,查看数据库是否添加的数据被删除;

4、原脚本如下:

*** Settings ***
Library DatabaseLibrary

*** Test Cases ***
Database_select查询
#链接数据库
Connect To Database Using Custom Params pymysql db="test",user="root",password="123456",host="localhost",port=3306
${select} Query SELECT * FROM student WHERE id = 4
log ${select}
Disconnect From Database

Database_insert插入
#链接数据库
Connect To Database Using Custom Params pymysql db="test",user="root",password="123456",host="localhost",port=3306
${insert} Execute Sql String INSERT INTO student(id,name,age,address) values(4,'小米','23','北京')
log ${insert}
Disconnect From Database

Database_update更新
#链接数据库
Connect To Database Using Custom Params pymysql db="test",user="root",password="123456",host="localhost",port=3306
${update} Execute Sql String UPDATE student SET name='oppo' WHERE id = 4
log ${update}
Disconnect From Database

Database_delete删除
#链接数据库
Connect To Database Using Custom Params pymysql db="test",user="root",password="123456",host="localhost",port=3306
${delete} Execute Sql String DELETE FROM student WHERE id = 4
log ${delete}
${select} Query SELECT * FROM student WHERE id = 4
log ${select}
Disconnect From Database