使用 Json 文件的 Jmeter 请求 - 操作 Json 文件

问题描述 投票:0回答:1

我必须创建一个 Jmeter 脚本来使用来自 json 的信息(`

{
    "enabled": true,
    "sort": null,
    "description": null,
    "external_id": null,
    "name": "Country",
    "id": "cac65eb2-d443-4f77-afc5-379c37750a2f",
    "values": [
        {
            "enabled": true,
            "sort": 4,
            "external_id": null,
            "name": "World",
            "id": "295e9c1a-2cbc-445f-aa5e-c1ac409953b3",
            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
            "parent": null,
            "attributes": [
                {
                    "id": 1546,
                    "enabled": true,
                    "rights_matrix_attributes_id": {
                        "id": "3457484a-fe54-4243-ba18-963b55d527e3",
                        "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                        "name": "Geoblocking",
                        "sort": null,
                        "source": null,
                        "type": "Switch"
                    }
                },
                {
                    "id": 1547,
                    "enabled": true,
                    "rights_matrix_attributes_id": {
                        "id": "fec573bd-56a5-46bf-a475-f1a7088301d0",
                        "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                        "name": "Geoblocking Methods Allowed",
                        "sort": null,
                        "source": "geoblocking_methods",
                        "type": "Dropdown"
                    }
                },
                {
                    "id": 1548,
                    "enabled": true,
                    "rights_matrix_attributes_id": {
                        "id": "cdd1a096-f84d-478c-9922-3dac6db2c06a",
                        "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                        "name": "Overspill",
                        "sort": null,
                        "source": null,
                        "type": "Switch"
                    }
                }
            ],
            "children": [
                {
                    "enabled": true,
                    "sort": 0,
                    "external_id": null,
                    "name": "Europe",
                    "id": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                    "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                    "parent": "295e9c1a-2cbc-445f-aa5e-c1ac409953b3",
                    "attributes": [],
                    "children": [
                        {
                            "enabled": true,
                            "sort": -1,
                            "external_id": null,
                            "name": "Italy",
                            "id": "d8b009a1-db39-4b9c-82aa-61946728cdc6",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 1,
                            "external_id": null,
                            "name": "Spain",
                            "id": "ade3569b-a2fa-456d-a816-54740ffdc7c1",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 4,
                            "external_id": null,
                            "name": "Austria",
                            "id": "ff2642cc-101b-4ab8-9e3f-6bef9e99a3d8",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 4,
                            "external_id": null,
                            "name": "Portugal",
                            "id": "ef4666fa-cb6b-4c98-afa4-a0bd82f76008",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 4,
                            "external_id": null,
                            "name": "Denmark",
                            "id": "edd11da2-5ebe-4969-9a74-8d229d4df1d1",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 4,
                            "external_id": null,
                            "name": "France",
                            "id": "70ebade9-674a-45da-8215-33a72161192f",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 4,
                            "external_id": null,
                            "name": "Poland",
                            "id": "1402e269-96ef-49af-b7dd-a04c80a22401",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "ff6fa181-22a6-484c-acd9-c802ff5b0a63",
                            "attributes": [],
                            "children": []
                        }
                    ]
                },
                {
                    "enabled": true,
                    "sort": 0,
                    "external_id": null,
                    "name": "Asia",
                    "id": "a2b259ce-ce7d-456b-943e-74522ead0cc9",
                    "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                    "parent": "295e9c1a-2cbc-445f-aa5e-c1ac409953b3",
                    "attributes": [],
                    "children": [
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Japan",
                            "id": "af9ce4db-7a93-4cde-96c5-00bdaff11280",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "a2b259ce-ce7d-456b-943e-74522ead0cc9",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Thailand",
                            "id": "215bc143-6833-4449-99c6-57a61bb6630f",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "a2b259ce-ce7d-456b-943e-74522ead0cc9",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "China",
                            "id": "12eb5afa-aab1-4a9d-8963-b206874233a3",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "a2b259ce-ce7d-456b-943e-74522ead0cc9",
                            "attributes": [],
                            "children": []
                        }
                    ]
                },
                {
                    "enabled": true,
                    "sort": 0,
                    "external_id": null,
                    "name": "Oceania",
                    "id": "96edeb00-e0b2-45e8-8a86-b643f3844ac1",
                    "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                    "parent": "295e9c1a-2cbc-445f-aa5e-c1ac409953b3",
                    "attributes": [],
                    "children": [
                        {
                            "enabled": true,
                            "sort": -1,
                            "external_id": null,
                            "name": "Australia",
                            "id": "485932e1-4590-4f07-8eb5-ed06e531bfad",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "96edeb00-e0b2-45e8-8a86-b643f3844ac1",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 1,
                            "external_id": null,
                            "name": "New Zeland",
                            "id": "7826526e-445a-4bc9-9677-a4b837a96097",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "96edeb00-e0b2-45e8-8a86-b643f3844ac1",
                            "attributes": [],
                            "children": []
                        }
                    ]
                },
                {
                    "enabled": true,
                    "sort": 0,
                    "external_id": null,
                    "name": "America",
                    "id": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                    "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                    "parent": "295e9c1a-2cbc-445f-aa5e-c1ac409953b3",
                    "attributes": [],
                    "children": [
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Canada",
                            "id": "fbe84911-21e4-408b-8862-a3f42b9757c4",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Brazil",
                            "id": "d8c9bef5-4363-404f-9515-920bd1da0c82",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "United States",
                            "id": "879db053-d151-4625-b326-6e32abfb4da0",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Mexico",
                            "id": "78f0fbd3-4ece-4ad5-9c10-df953737f3f4",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                            "attributes": [],
                            "children": []
                        },
                        {
                            "enabled": true,
                            "sort": 0,
                            "external_id": null,
                            "name": "Argentina",
                            "id": "6b1f9421-665a-4fb8-b3ce-fbcb2862f0fa",
                            "dimension": "cac65eb2-d443-4f77-afc5-379c37750a2f",
                            "parent": "280c614b-332e-4759-a9a3-2b83a6d0920e",
                            "attributes": [],
                            "children": []
                        }
                    ]
                }
            ]
        }
    ]
}

我想提取所有单个值,包括子项,但我想排除属性。然后我必须在单个 POST 请求(值创建)中使用提取的单个父/子值(不带属性),然后我必须在 PATCH 请求(值更新)中包含单个值及其属性(我不这样做)不知道如何提取它们),然后我必须发出另一个 PATCH 请求(将子值添加到父值),并且我需要单个值的 id 和子值的 id。我知道这有点棘手:)。请求的数量必须遵循值的数量。我认为可以在同一请求中添加属性和子项。价值观 孩子可以生孩子。谢谢 :) 发布请求正文:(

{"name":"Italian","enabled":true,"dimension":"9afe6729-0d9c-4d7d-be40-5ec3e308f2e3","consumption_type":null, "id": "cac65eb2-d443-4f77-afc5-379c37750a2f", "sort": null, "description": null,"external_id": null}

第一个 PATCH 请求将属性添加到值:

{"enabled":true,"sort":0,"external_id":null,"name":"Italian","date_updated":null,"date_created":"2023-09-13T10:24:36.584Z","consumption_type":null,"user_updated":null,"user_created":"2eea50dc-ffff-4fdf-8593-238ffde6d8c1","id":"39568be1-f909-4320-b53c-5fbfaa3c0504","dimension":"9afe6729-0d9c-4d7d-be40-5ec3e308f2e3","attributes":[{"enabled":true,"rights_matrix_attributes_id":{"id":null,"name":"Prova","type":"Input","source":null}}]}

第二个 PATCH 请求有效负载添加子值:

{"dimension":"9afe6729-0d9c-4d7d-be40-5ec3e308f2e3","id":"39568be1-f909-4320-b53c-5fbfaa3c0504","children":["6d9dd3e3-38a0-49a8-85e6-c167256e2fbd"]}

json post jmeter patch jmeter-5.0
1个回答
0
投票

我无法看到这 3 个请求如何与您获得的响应相关联,因为属性值不同,并且不清楚它们是来自原始响应还是生成的。

例如,“信息”中任何地方都没有

Italian
,“信息”中任何地方都没有维度
9afe6729-0d9c-4d7d-be40-5ec3e308f2e3
,等等

您很可能需要使用 JSR223 PostProcessorGroovy 语言 生成请求正文。有关更多详细信息,请参阅解析和生成 JSON 文章。

© www.soinside.com 2019 - 2024. All rights reserved.