加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 16:43:59 所属栏目:大数据 来源:网络整理
导读:1, 写入值(30,31),更新到数据表的多条记录。 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()

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


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<strAry.size();i++)

{

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

log.info(sqlStr)

sqlResult = sql.firstRow(sqlStr)

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

assert sqlResult.cnt == 1

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读