Json 提取唯一数据 - Jmeter

Json extract unique data - Jmeter

我的线程组中有一组请求,其中第一个请求将为第二个请求提供输入。我正在使用 json 提取器(匹配号 0)从列表中提取值。我想确保在后续线程运行中不会获取在线程 1 中提取的相同数据。你能建议如何处理吗?

根据JSON Extractor documentation

If the JSON Path query leads to many results, you can choose which one(s) to extract as Variables:

0 : means random (Default Value)

“随机”不能保证唯一性,因此如果您需要数据是唯一的 - 请考虑为该“匹配号”字段提供递增的值。

示例设置:

  1. 给出以下 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
    }
    
  2. 假设您要使用唯一的书名,即

    • Sayings of the Century - 第一次迭代
    • Sword of Honour - 第二次迭代
    • 等等
  3. 将“匹配号”字段值修改为:

    ${__intSum(${__jm__Thread Group__idx},1,)}
    

    其中 __jm__Thread Group__idx 是可用的预定义变量,因为 JMeter 4.0 which returns current Thread Group iteration and __intSum() 是 JMeter 函数,它将 1 添加到迭代次数(因为它是从零开始的)

    完整的 JSON 提取器配置类似于:

  4. 基本上就是这样,现在您有信心为每个线程组迭代获取新值,可以使用 View Results Tree 侦听器进行检查。