【发布时间】:2019-03-19 17:22:40
【问题描述】:
我的线程组中有一组请求,其中第一个请求将为第二个请求提供输入。我正在使用 json 提取器(匹配 No.0)从列表中提取值。我想确保在后续线程运行中不会获取在线程 1 中提取的相同数据。你能建议如何处理吗?
【问题讨论】:
标签: jmeter jmeter-plugins
我的线程组中有一组请求,其中第一个请求将为第二个请求提供输入。我正在使用 json 提取器(匹配 No.0)从列表中提取值。我想确保在后续线程运行中不会获取在线程 1 中提取的相同数据。你能建议如何处理吗?
【问题讨论】:
标签: jmeter jmeter-plugins
根据JSON Extractor documentation
如果 JSON 路径查询导致许多结果,您可以选择提取哪些作为变量:
0:表示随机(默认值)
“随机”并不能保证唯一性,因此如果您需要数据唯一 - 请考虑为此“匹配号”字段提供递增值。
示例设置:
鉴于以下 JSON
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
假设您想使用唯一的书名,即
Sayings of the Century - 第一次迭代Sword of Honour - 第二次迭代将“匹配号”字段值修改为如下所示:
${__intSum(${__jm__Thread Group__idx},1,)}
其中__jm__Thread Group__idx 是自JMeter 4.0 以来可用的预定义变量,它返回当前Thread Group 迭代,__intSum() 是JMeter 函数,它将1 添加到迭代数(因为它是从零开始的)
完整的 JSON 提取器配置类似于:
基本上就是这样,现在您确信每次线程组迭代都会获取新值,可以使用 View Results Tree listener 来检查它。
【讨论】:
Thread Group 不同,则需要修改变量,如 ${__jm__put-your-thread-group-name-here__idx}