如何使用空手道合并 2 个 JSON 负载

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

在我的项目中,需要我从Endpoint 1获取user_id,

然后与端点 2 中的会话数据合并。

输入1:

    {_user_id: "user1"}

输入2:

    {
    "_session_id": "5182d9fe-1f4f-484b-88c2-708f32cdd661"
    },
    {
    "_session_id": "372cf574-2526-41ed-9a9b-77ecc50b0d66"
    }

预期产量

    {
    "_user_id: "user1",
    "_session_id": "5182d9fe-1f4f-484b-88c2-708f32cdd661"
    },
    {
    "_user_id: "user1",
    "_session_id": "372cf574-2526-41ed-9a9b-77ecc50b0d66"
    }

空手道有办法实现这一点吗?

karate
1个回答
1
投票

请使用空手道中设置的关键字

Feature: Merge JSON Payloads from different end points

  Scenario: Merge JSON Payloads

    * def response1 =  { "_user_id": "user1" }
    * print response1

    * def response2 =
    """
    [
    {
    "_session_id": "5182d9fe-1f4f-484b-88c2-708f32cdd661"
    },
    {
    "_session_id": "372cf574-2526-41ed-9a9b-77ecc50b0d66"
    }
    ]
    """
    * print response2

    * set response2[0]._user_id = response1._user_id
    * set response2[1]._user_id = response1._user_id
    * print response2

HTML 报告 enter image description here

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