【发布时间】:2021-03-03 12:03:36
【问题描述】:
从下面的响应结构中,我想检索 id 字段并将其保存在邮递员的环境变量中。
我尝试了所有可能的方法,但无法做到。
{
"childMaxAge": 13,
"selectedForBooking": [
{
"id": "0661be61-d0ae-411009-a96d-64229a",
"firstName": "Test",
"gender": {
"code": "MALE",
"name": "Male"
}
]
}
我尝试了以下方法,它也不起作用。
tests["Status code is 201"] = responseCode.code === 201;
var data = JSON.parse(responseBody);
console.log(data);
var custid=JSON.parse(data.selectedForBooking[0].id);
tests ["selectedForBooking"]= postman.setEnvironmentVariable("CustId1", custid);
但它给出了错误:
评估测试脚本时出错:JSONError: Unexpected token '6' at 1:2 0661be61-d0ae-411009-a96d-64229a ^
【问题讨论】:
标签: parameters postman