admin 管理员组文章数量: 1086019
I have JSON like below:
{
"success": true,
"code": 200,
"message": "Success",
"data": [
{
"ID_A": "AXCS-1-1",
"ID_B": "AXCS-1-1",
"Number": "11009988"
}
]
}
And my script for testing in postman:
var data = JSON.parse(responseBody);
if(responseCode.code === 200){
pm.environment.set("IdA",data.data[0].ID_A);
pm.environment.set("IdB",data.data[0].ID_B);
}
And I get the response:
How to fix this?
I have JSON like below:
{
"success": true,
"code": 200,
"message": "Success",
"data": [
{
"ID_A": "AXCS-1-1",
"ID_B": "AXCS-1-1",
"Number": "11009988"
}
]
}
And my script for testing in postman:
var data = JSON.parse(responseBody);
if(responseCode.code === 200){
pm.environment.set("IdA",data.data[0].ID_A);
pm.environment.set("IdB",data.data[0].ID_B);
}
And I get the response:
How to fix this?
Share Improve this question edited Apr 15, 2022 at 8:49 slhck 38.9k33 gold badges160 silver badges218 bronze badges asked Apr 15, 2022 at 8:11 DefandiDefandi 1241 gold badge1 silver badge6 bronze badges 3-
you have a typo:
data.code
notresponseCode.code
– rcshon Commented Apr 15, 2022 at 8:37 -
Thats don't work when i change
data.code
fromresponseCode.code
– Defandi Commented Apr 15, 2022 at 8:51 -
1
Just a general question, why have you used
JSON.parse(responseBody)
in the script? Have you followed a tutorial? Do you know aboutpm.response.json()
? – Danny Dainton Commented Apr 15, 2022 at 12:21
1 Answer
Reset to default 6The error says responseBody is not defined and the error is from prerequest script
responseBody is a global object that contains the response , this variable is available only in test script , and as pre-request is executed before the request is even send, requestBody variable wont be accessible
本文标签: javascriptresponseBody is not defined in PostmanStack Overflow
版权声明:本文标题:javascript - responseBody is not defined in Postman - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744085056a2530966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论