soapUI+groovy接口测试之部分groovy使用记录

1, 写入值(30,31),更新到数据表的多条记录。

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比大荔网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式大荔网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖大荔地区。费用合理售后完善,十载实体公司更值得信赖。

sqlStr ="select column_id from 1dcq_shop_column2  where shop_id = '"+ db_Shop_id + "'"

def dbSettings=[]

def db_sub_column_id =""

sqlResult = sql.eachRow(sqlStr)

{

dbSettings << it.toRowResult() 

}

 

for (i=0;i< dbSettings.size;i++)

{

db_sub_column_id = db_sub_column_id.toString() + dbSettings[i].column_id.toString()

if (i < dbSettings.size-1)

{

db_sub_column_id=db_sub_column_id+","

}

}

assert subColumnId == db_sub_column_id

2,初始化数据

import groovy.sql.Sql

//import groovyx.net.http.ContentType

log.info("-------------------------------------------------The Test Step start ---------------------------------------------")

/*            

*             1,获取数据库连接参数,连接数据库

*/

def tpProperties = testRunner.testCase.getProject()

def tsProperties = testRunner.testCase.getTestSuite()

def tcProperties = testRunner.getTestCase()

def service_ip= tpProperties.getPropertyValue( "YDGJ_IP" )

def refreshPath = tpProperties.getPropertyValue( "refreshPath" )

def db_url = tpProperties.getPropertyValue( "DB_Connection_URL" )

def db_user = tpProperties.getPropertyValue( "DB_loginname" )

def db_pwd = tpProperties.getPropertyValue( "DB_Password" )

def db_driver = tpProperties.getPropertyValue( "DB_Driver_Class" )

def sql = Sql.newInstance(db_url,db_user,db_pwd,db_driver)

     log.info("------ 1,获取数据库连接参数,连接数据库 finished")

     

/*            

*             2,初始化数据库表

*/

// begin 初始化数据

def sqlStr = "call sp_easydata_genAll()"

log.info("自动生成业务数据 : " +  sqlStr)

sql.execute(sqlStr)

log.info("------ 2,初始化表基础数据 finished")

/*            

*             3,设置补充用例所需表数据

*/

 

/*

def sqlStr = "select first 1 from "

log.info(sqlStr)

sql.execute(sqlStr);

*/

log.info("------ 3,设置补充用例所需表数据 finished, (请根据业务设置!)")

/*            

*             4,设置 或 从数据表获取 用例参数值

*/

//设置数据-必填

def curTime = System.currentTimeMillis()

//log.info("curTime:" + curTime)

def shopName= "shopName"+curTime

log.info(shopName)

tcProperties.setPropertyValue( "shopName", shopName) 

tcProperties.setPropertyValue( "userId", "2916011") 

tcProperties.setPropertyValue( "shopkeeper","店主姓名呀") 

tcProperties.setPropertyValue( "provinceId","360000") 

3, 通过设置变量,获取变量完成值传递

def tpProperties = testRunner.testCase.getProject()

def tsProperties = testRunner.testCase.getTestSuite()

def tcProperties = testRunner.getTestCase()

def shopName = tcProperties.getPropertyValue("shopName" )

def userId = tcProperties.getPropertyValue("userId" )

def shopkeeper = tcProperties.getPropertyValue("shopkeeper" )

def provinceId = tcProperties.getPropertyValue("provinceId" )

三,string 用split 处理成数组

log.info("skillsCertificateNos: " + skillsCertificateNos)

String[] strAry = skillsCertificateNos.split(",");

log.info ("strAry.size():" + strAry.size())

for (i=0;i

{

sqlStr ="select count(*) as cnt from 1dcq_p_w_upload  where file_no = '"+ strAry[i] + "'"

log.info(sqlStr)

sqlResult = sql.firstRow(sqlStr)

log.info ("skillsCertificateNos,,,,,,,,sqlResult.cnt : " + sqlResult.cnt)

assert sqlResult.cnt == 1

}


本文名称:soapUI+groovy接口测试之部分groovy使用记录
本文URL:http://myzitong.com/article/josopp.html