JMeter-无法将Dynamics CSV值获取到我的JsonBuilder请求正文中



昨天我问了一个关于在JMeter上创建带有预处理器的动态请求体的问题。多亏了德米特里·T,我几乎得到了我想要的。

这里的老问题:JMeter创建一个预处理器,它将基于用户定义的变量生成请求体


但现在,我无法将CSV文件中的动态值获取到请求正文中。

MY CSV文件示例数据:

Reading CSV successfully finished, 20 records found:
${id} = 1000011
${email} = a1000011@smartmessage.com
------------
${id} = 1000012
${email} = a1000012@smartmessage.com
------------
${id} = 1000013
${email} = a1000013@smartmessage.com

生成请求正文的我的预处理器:

import groovy.json.JsonBuilder;

def payload = [:]
def X = 10 // read user input here somehow

payload.put('message_job_id', '28b0a005-9ef1-475c-b33c-ade900f19e4c')
payload.put('campaign_group', 'Entegrasyon')
payload.put('template_id', 'cf585c8c-c675-40d2-b88a-ade900c898d5')

def recipient_list = []
1.upto(X, { x ->
def recipient = [:]
recipient.put('customer_id', vars.get('id') + x)
def target = [:]
def address = ['address': vars.get('email' + x)]
target.put('target', address)
recipient.put('target', target)
recipient_list.add(recipient)
})

payload.put('recipient_list', recipient_list)


vars.put('payload', new groovy.json.JsonBuilder(payload).toPrettyString())

查看结果树中我生成的请求正文:

{
"message_job_id": "28b0a005-9ef1-475c-b33c-ade900f19e4c",
"campaign_group": "Entegrasyon",
"template_id": "cf585c8c-c675-40d2-b88a-ade900c898d5",
"recipient_list": [
{
"customer_id": "10000111",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000112",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000113",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000114",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000115",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000116",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000117",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000118",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "10000119",
"target": {
"target": {
"address": null
}
}
},
{
"customer_id": "100001110",
"target": {
"target": {
"address": null
}
}
}
]
}

正如您所看到的,地址键总是空值,但我想在CSV文件中用电子邮件变量填充这个键。

如果您需要从CSV文件构建一个请求主体,并从"一次性"-使用CSV数据集配置和衍生工具将无法实现这一点,因为CSV数据集设置会为每个用户的每次迭代读取下一行。

如果需要在单个迭代的范围内读取多行,则需要切换到__CSVRead((函数,或者直接在Groovy中从CSV文件中读取数据。

相关内容

  • 没有找到相关文章

最新更新