我使用Soup 'JDBC请求‘选项来检查db结果。我通常使用参数作为
param = ${step name#request param}
并在sql as select * from db where param = :param中使用它,这对于特定的param非常有用。但是当我尝试使用逗号分隔param (例如1000,10001,10003)时,sql查询首先运行,1000。
即有一个请求参数,名为ID,值为1000,10001,10003,我创建一个JDBC参数为IDs =${ name#IDs},并将sql查询创建为select * from db where id in (:IDs),它只获得逗号分隔参数的第一条记录。因此,我想知道如何使用逗号划分的JDBC参数和sql select一起使用,因为我从上一步请求param获得了方便的ui参数,如:图像。

发布于 2017-11-03 11:00:44
下面是使用多值in子句发送查询的方式。
IDS,并根据需要提供值(如问题中所述,用逗号分隔)${#TestCase#IDS}相同的query重写并不重要。in子句设置计算查询。Groovy脚本:遵循内联注释。
import groovy.text.SimpleTemplateEngine
//Edit the jdbc test step name if required
def nextStep = 'Compare with db results'
//Edit query if required, but not ids variable below as that is used in binding
def query = 'select * from job where id in ( $ids )'
def binding = [ids: context.testCase.getPropertyValue('IDS')]
def step = context.testCase.testSteps[nextStep]
def template = new SimpleTemplateEngine().createTemplate(query).make(binding)
log.info "updated query : ${template.toString()}"
//Set the query to jdbc step
step.jdbcRequestTestStepConfig.query = template.toString()运行测试用例时,groovy脚本步骤将查询设置为jdbc请求。
注意:如果jdbc测试步骤是打开的,只需关闭它并重新打开以查看更新的查询。
https://stackoverflow.com/questions/46949726
复制相似问题