Foreach无法在带有JSON提取器的JMeter中工作

mrphzbgm  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(151)

有了下面的响应负载,我想获取Order NumberTotal Order Number并将其传递给for each控制器,但它不工作。
我能够获取总数,但无法将其传递给每个控制器,可能是在变量赋值中出现了一些错误,

{
    "orderDetails": {
        "orderCode": 490278,
        "studyCode": "test_2"
    },
    "sites": [
        {
            "orderCode": 490278,
            "siteRecid": 16521,
            "siteId": "11001"
        }
    ],
    "orders": [
        {
            "orderNumber": 4027,
            "siteName": "flipKart",
            "siteNameCode": "flipKart",
            "orderAmount": 10
        },
        {
            "orderNumber": 4590,
            "siteName": "flipKart_1",
            "siteNameCode": "flipKart 1",
            "orderAmount": 20
        },
        {
            "orderNumber": 1678,
            "siteName": "flipKart_2",
            "siteNameCode": "flipKart 2",
            "orderAmount": 30
        },
        {
            "orderNumber": 1762,
            "siteName": "flipKart_3",
            "siteNameCode": "flipKart 3",
            "orderAmount": 40
        },
        {
            "orderNumber": 1566,
            "siteName": "flipKart_4",
            "siteNameCode": "flipKart 4",
            "orderAmount": 50
        },
        {
            "orderNumber": 1432,
            "siteName": "flipKart_5",
            "siteNameCode": "flipKart 5",
            "orderAmount": 60
        },
        {
            "orderNumber": 1089,
            "siteName": "flipKart_6",
            "siteNameCode": "flipKart 6",
            "orderAmount": 70
        },
        {
            "orderNumber": 9078,
            "siteName": "flipKart_7",
            "siteNameCode": "flipKart 7",
            "orderAmount": 80
        },
        {
            "orderNumber": 4508,
            "siteName": "flipKart_8",
            "siteNameCode": "flipKart 8",
            "orderAmount": 90
        },
        {
            "orderNumber": 4278,
            "siteName": "flipKart_9",
            "siteNameCode": "flipKart 9",
            "orderAmount": 100
        },
        {
            "orderNumber": 9028,
            "siteName": "flipKart_10",
            "siteNameCode": "flipKart 10",
            "orderAmount": 110
        }
    ]
}

取订单总数,

对于每个控制器都没有运行。提前感谢

mspsb9vt

mspsb9vt1#

它工作正常,在ForEach控制器中,您只需要使用OrderNumberTotal,而不需要使用${},请查看ForEach控制器文档示例屏幕截图:

存在inputVar之类的变量名,而不是${inputVar}之类的变量引用

还应注意,从JMeter 3.1开始,您应该使用JSR223测试元素和Groovy语言编写脚本,因此请考虑迁移。
更多信息:Apache Groovy: What Is Groovy Used For?

相关问题