SoapUI中使用Groovy脚本操作数据库 .
来源:互联网 发布:装修自动设计软件 编辑:程序博客网 时间:2024/05/05 08:43
1:在SoapUI中放置第三方Jar包
连接的数据库的jar包需要放置于bin/ext目录下
原文如下:
If you need to add external libraries to the soapUI classpath for your Groovy scripts (for example jdbc drivers), put these in the bin/ext folder under the soapUI installation, these will be read upon started and added to the soapUI classloader.
2: 在SoapUI的Test Case中新增数据库连接的配置,此配置的Properties文件可以直接从本地文件中导入
3:在SoapUI的Test Case中新建Groovy Script连接数据库
接口如下
def sql = Sql.newInstance(
地址,
用户名,
密码,
驱动 )
实现样例如下:
import groovy.sql.Sql
//通过读取配置文件连接数据库
def DBProperties = testRunner.testCase.getTestStepByName( "DBProperties" );
def sql = Sql.newInstance(DBProperties.getPropertyValue( "connection-url" ),DBProperties.getPropertyValue( "sysdb-user-name" ),
DBProperties.getPropertyValue( "sysdb-password" ),DBProperties.getPropertyValue( "driver-class" ))
4:在SoapUI中通过Groovy脚本操作数据库
1)删除和新建表
//删除表
try {
sql.execute("drop table PERSON")
} catch(Exception e){}
//新建表
sql.execute('''create table PERSON (
id integer not null primary key,
firstname varchar(20),
lastname varchar(20),
location_id integer,
location_name varchar(30)
)''')
2)插入记录
插入记录有两种方式
//向表中插入记录
sql.execute("insert into PERSON (id,firstname,lastname,location_id,location_name) values (1,'gao','shuaihong',1,'hshen') ")
//插入记录另外一种方式
def people = sql.dataSet("PERSON")
people.add( firstname:"James", lastname:"Strachan", id:4, location_id:10, location_name:'London' )
3)查询记录
//选择一行记录
def gaoshuaihong = sql.firstRow("select * from PERSON where id = 1")
log.info(gaoshuaihong.firstname)
//选择多条记录
def allPerson = sql.rows(" select * from PERSON")
log.info(allPerson)
log.info(allPerson[0])
sql.eachRow("select * from PERSON"){ row ->
log.info(row.lastname)
}
4)校验结果
assert allPerson[0].lastname== "shuaihong"
另外通过Groovy的Sql还支持操作存储过程.
- SoapUI中使用Groovy脚本操作数据库 .
- SoapUI中使用Groovy脚本操作数据库
- SoapUI中使用Groovy脚本操作数据库
- 【SoapUI】在soapui中使用Groovy脚本常用方法
- SoapUI自动化--Groovy脚本常用操作
- SoapUI中使用Groovy修改请求消息&校验返回消息
- SoapUI中使用Groovy修改请求消息&校验返回消息
- soapUI+groovy 接口测试之部分groovy使用记录
- SoapUI用groovy脚本提取json数组数据
- SoapUI用groovy脚本提取json数组数据
- SoapUI自动化--Groovy脚本实现随机抽取DataSource(Excel)
- groovy脚本使用map
- Groovy 操作mysql数据库
- groovy进行数据库操作
- SoapUI利用Groovy把外部数据加载到request中
- SoapUI利用Groovy把外部数据加载到request中
- SOAPUI 使用groovy发送http请求 自动化测试
- Groovy and SoapUI
- 《算法竞赛-训练指南》第一章-1.19_UVa 11549
- C++笔记
- HDU-2007
- 省赛到暑假集训小结
- poj2186Popular Cows(强连通+缩点)
- SoapUI中使用Groovy脚本操作数据库 .
- java.lang.NoClassDefFoundError: com.umeng.analytics.MobclickAgent 解决方法
- C与C++地址分配函数malloc与new
- Myeclipse中的快捷键
- Gridx Reload 重置
- 【rzxt】笔者支招:Win8系统搜索不到无线信号该怎么办?
- 16进制数逆序输出
- java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gaobo.e5community/com.g
- Android TextView 45°倾斜效果