【问题标题】:PostMan: How can I copy an array/segment from one response to the next request?PostMan:如何将数组/段从一个响应复制到下一个请求?
【发布时间】:2019-02-22 04:56:19
【问题描述】:

第一次发帖! 我一直在玩邮递员自动化并设法复制 ID 字符串和 FAB Id。 我看到有人问过类似的问题,但并没有突出我希望如何做到这一点......

可用性响应;

<SessionInfo FABSessionId="FAB123456789"/>
<VehicleSearchResponse Success="true" ModifiedRequest="false">
    <ViewInfo Offset="0" Length="30"/>
    <ResultSetInfo SortCode="cost" SortAscending="true" MaxItems="900" NumItems="30"/>
    <Vehicles>
        <Vehicle StartDate="20181002" EndDate="20181006" PickUpPoint="XXX" DropOffPoint="XXX">
            <Image URL="https://picture.net/example.jpg"/>
            <MoreInfoTexts>
                <MoreInfo Header="..."/>
                <MoreInfo Header="..."/>
                <MoreInfo Header="..."/>
            </MoreInfoTexts>
            <PickUpDepotDetails Telephone="012345 67890">
                <Address Address1="..." CityOrTown="..." Country="..."/>
            </PickUpDepotDetails>
            <DropOffDepotDetails Telephone="012345 67890">
                <Address Address1="..." CityOrTown="..." Country="..."/>
            </DropOffDepotDetails>
        </Vehicle>
........
 </Vehicles>
</VehicleSearchResponse>

见上文...我希望能够将整个“车辆”部分从可用性响应复制到成本计算请求...它是一个数组,因此下面还有 20 个其他结果......

成本核算要求:

<Itinerary EndDate="20181006" ItineraryId="V!XXX!12345!ABC123!XXX!ABC321!XXX" StartDate="20181002">
<Vehicles>
            {{vehicleSetter}}
</Vehicles>
<OptionalExtras>

因此需要将整个 Vehicle - /Vehicle 段复制到 {{vehicleSetter}}。

有没有办法使用类似的(成本核算)Pre-RQ 脚本来做到这一点;

pm.globals.get("fabSessionSetter");

pm.globals.get("vehicleSetter");

也许在 (Avail.) Tests 脚本中有些东西,比如

pm.globals.set("vehicleSetter", jsonObject.FAB_VehicleAvailRS.VehicleSearchResponse.Vehicles.Vehicle[2]);

如果您需要更多信息,请告诉我...谢谢!

【问题讨论】:

    标签: json xml api automation postman


    【解决方案1】:

    首先,我会要求开发人员使用 json 类型的数据而不是 XML 来传递数据。方便多了,我是在乞求开发一个新项目的时候走这条路的,它给我带来了很多好处。但万一你的情况是可能的。 不用全局变量,环境变量就够了。

    但是试试这个,我从来没有这样做过,但也许它会帮助你。 https://github.com/cheeriojs/cheerio https://www.w3schools.com/xml/xpath_syntax.asp

    【讨论】:

      【解决方案2】:

      我想我遇到了和你类似的问题,不得不将 json 转换为 xml,无论哪种方式我都得到了 Sivcan Singh 的精彩回应

      Convert XML to JSON for extracting data then convert JSON back to XML in Postman

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-08
        • 2022-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多