测试计划结构
TestPlan
JDBC Connection Configuration
HTTP Request Defaults
HTTP Header Manager
User Defined Values
udvBranchCode
TestFragment
JDBCRequest - Written query to get data from database
JSR223 PostProcessor
ThreadGroup - CreateTransaction
IFController - ${__jexl3("${udvBranchCode}"== "",)} If udvBranchCode is blank then only run JDBCRequest
ModuleController - Pointed to JDBCRequest JSR223 PostProcessor
HttpRequest
JSR223 PreProcessor - Here checking I am checking if udvBranchCode has value; if not then value from the database will get set.
下面是详细信息1. JDBCRequest的JSR223后处理器
这里我正在检查resultSet的大小,然后将分支代码随机存储为属性。
resultSet = vars.getObject("resultSetUserDetails")
if (resultSet.size() !=0 ) {
Random random = new Random()
int i = random.nextInt(vars.getObject("resultSetUserDetails").size())
strBranchCode = vars.getObject("resultSetUserDetails").get(i).get("BranchCode")
props.put("propsBranchCode" + ctx.getThreadNum(), strBranchCode)
}
2。 HttpRequest详细信息 IFController
如果分支代码值在用户定义的值中为空,那么我正在调用数据库。
${__jexl3("${udvBranchCode}"== "",)}
{
"TR": {
"BranchCode": "${brnCode}" -> Here brnCode is not populating
"CustomerType": "${udvCustomerType}"
}
"Individual": {
"FirstName": "Deepak",
"MiddleName": "Kumar",
"LastName": "Verma",
}
"Company": {
"CompanyName": "Company",
"StartDate": "23/01/2020",
}
}
这里,我正在检查用户定义的值中是否不存在分支代码,然后设置从数据库获取的代码。同样基于客户类型,从请求中删除各个对象/元素也可以正常工作。但是对于BranchCode,我遇到了问题,这里不是填充BranchCode值,而是填充了“ $ {brnCode}”。
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def oldRequest = new JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def bcode = props.get("propsBranchCode" + ctx.getThreadNum())
if (vars.get("udvBranchCode").isEmpty() == true) {
vars.put("brnCode", bcode)
} else {
vars.put("brnCode", vars.get("udvBranchCode"))
}
if (oldRequest.Transaction.CustomerType.equalsIgnoreCase("Individual")) {
oldRequest.remove("Company")
}
def newRequest = new JsonOutput().toJson(oldRequest)
sampler.getArguments().removeAllArguments()
sampler.setPostBodyRaw(true)
sampler.addNonEncodedArgument('',new JsonOutput().prettyPrint(newRequest),'')
已通过替换为[[HttpRequest的JSR223预处理器详细信息]来解决此问题,>vars.put(“ brnCode”,bcode)与
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def oldRequest = new JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def bcode = props.get("propsBranchCode" + ctx.getThreadNum())
if (vars.get("udvBranchCode").isEmpty() == true) {
oldJSONRequest.TR.BranchCode = bcode
} else {
oldJSONRequest.TR.BranchCode = vars.get("udvBranchCode")
}
if (oldRequest.Transaction.CustomerType.equalsIgnoreCase("Individual")) {
oldRequest.remove("Company")
}
def newRequest = new JsonOutput().toJson(oldRequest)
sampler.getArguments().removeAllArguments()
sampler.setPostBodyRaw(true)
sampler.addNonEncodedArgument('',new JsonOutput().prettyPrint(newRequest),'')