soupuijdbc自定义参数定义
Soup ui jdbc custom parameter definition
我使用 Soup ui 'JDBC Request' 选择来检查数据库结果。我通常使用参数
param = ${step name#request param}
并将其用于
sql as select * from db where param = :param
这对于特定参数非常有用。但是当我尝试使用逗号分隔参数时,(例如 1000,10001,10003),sql 首先查询 运行,1000.
即有一个请求参数,其名称为 ID 和值 1000,10001,10003
我创建了一个 JDBC 参数作为 IDs = ${step name#IDs}
并将 sql 查询创建为 sql 作为
select * from db where id in (:IDs)
它只获取逗号分隔参数的第一条记录。
结果我想知道如何在 sql select 中使用逗号分隔的 JDBC 参数
我从上一步请求参数中得到 soup ui 参数为:
image
您可以通过以下方式发送包含多个值 in
子句的查询。
- 添加测试用例级别自定义 属性,例如
IDS
并根据需要提供值(如您在问题中提到的那样用逗号分隔)
- 在其余请求中,您也可以使用与
${#TestCase#IDS}
相同的方法
- 在jdbc请求测试步骤中,保持查询为空。没关系,从 groovy 脚本覆盖
query
.
- 在 jdbc 请求测试步骤之前添加一个 groovy 脚本测试步骤,并添加以下脚本,该脚本将设置具有多个值的计算查询(根据需要动态)
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 测试步骤已打开,只需将其关闭并重新打开以查看更新后的查询。
我使用 Soup ui 'JDBC Request' 选择来检查数据库结果。我通常使用参数
param = ${step name#request param}
并将其用于
sql as select * from db where param = :param
这对于特定参数非常有用。但是当我尝试使用逗号分隔参数时,(例如 1000,10001,10003),sql 首先查询 运行,1000.
即有一个请求参数,其名称为 ID 和值 1000,10001,10003
我创建了一个 JDBC 参数作为 IDs = ${step name#IDs}
并将 sql 查询创建为 sql 作为
select * from db where id in (:IDs)
它只获取逗号分隔参数的第一条记录。
结果我想知道如何在 sql select 中使用逗号分隔的 JDBC 参数
我从上一步请求参数中得到 soup ui 参数为:
image
您可以通过以下方式发送包含多个值 in
子句的查询。
- 添加测试用例级别自定义 属性,例如
IDS
并根据需要提供值(如您在问题中提到的那样用逗号分隔) - 在其余请求中,您也可以使用与
${#TestCase#IDS}
相同的方法
- 在jdbc请求测试步骤中,保持查询为空。没关系,从 groovy 脚本覆盖
query
. - 在 jdbc 请求测试步骤之前添加一个 groovy 脚本测试步骤,并添加以下脚本,该脚本将设置具有多个值的计算查询(根据需要动态)
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 测试步骤已打开,只需将其关闭并重新打开以查看更新后的查询。