执行以XML格式返回的GET请求。我将其转换为JSON,如下所示。我想解析一个数组并将数组设置为env。数组中每个特定对象的变量。]>
如何实现遍历Tuple.Answer,以从响应中获取每个对象的所有突出显示的值?使用当前的测试脚本,我在ActionIDs env变量中获得了以下内容:[“1965555”,“1965555”,“1965555”,“1965555”,“1965555”,“1965555”]
我要检索的数据路径:
BESAPI.Query.Result.Tuple.Answer[0]._
这是我的动作脚本:
var jsonData = xml2Json(responseBody); var ActionIDs = ; .each(jsonData.BESAPI.Query.Result.Tuple[0].Answer[0]., () => { ActionIDs.push(jsonData.BESAPI.Query.Result.Tuple[1].Answer[0]._) }) pm.environment.set(“ActionID”, ActionIDs.shift()); pm.environment.set(“ActionIDs”, JSON.stringify(ActionIDs)); pm.test(“Status code is 200”, function() { console.log(pm.response.code); pm.response.to.have.status(200); });
响应:
<?xml version="1.0" encoding="UTF-8"?>
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
<Query Resource="(id of it, name of it, state of it) of bes actions">
<Result>
<Tuple>
<Answer type="integer">1965354</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (1/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965555</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (2/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965761</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (3/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1965962</Answer>
<Answer type="string">Test Policy 2: Test Policy Azure Test: (4/4)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967153</Answer>
<Answer type="string">Image: Windows Images: (1/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967354</Answer>
<Answer type="string">Image: Windows Images: (2/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967555</Answer>
<Answer type="string">Image: Windows Images: (3/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967756</Answer>
<Answer type="string">Image: Windows Images: (4/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1967957</Answer>
<Answer type="string">Image: Windows Images: (5/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
<Tuple>
<Answer type="integer">1968158</Answer>
<Answer type="string">Image: Windows Images: (6/6)</Answer>
<Answer type="string">Open</Answer>
</Tuple>
</Result>
<Evaluation>
<Time>8.844ms</Time>
<Plurality>Plural</Plurality>
</Evaluation>
</Query>
</BESAPI>
执行以XML格式返回的GET请求。我将其转换为JSON,如下所示。我想解析一个数组并将数组设置为env。 ...
类似这样的事情应该将这些ID存储为环境变量: