Hello, i’m trying to check the value of an attribute returned by get request. I want to check that the status is correct, and versión.
For example:
{
"id": "XXXXX",
"statuses": [
{
"version": 1,
"user": "AAAAA",
"department": "BBBBB",
"status": "CCCCC",
"action": "DDDDD",
"date": "2021-03-29 07:21:21 +0000",
"last": false
},
{
"version": 2,
"user": "EEEEE",
"department": "FFFFFF",
"status": "JJJJJ",
"action": "KKKKK",
"date": "2021-03-29 07:22:46 +0000",
"last": true
}
]
}
Hello there,
Welcome to the community
I didn’t understand your question properly.
If you want to access version and status.
You can access them like this.
First save the response in the test script.
var response = pm.response.json();
then
response.statuses.forEach(status => {
const version = status.version;
const stat = status.status;
)}
I hope this will help you.
If you have any other questions, feel free to ask.
thefierycoder:
onse.statuses.forEach
I want to check the value, for example that the response contains the version 1 and 2, and the status X and Y.
Thansk for all!
Hi @alejandroescribano similar to @thefierycoder code you can try to add the below assertion to get the version and status
for (var i=0; i<resp.statuses.length; i++)
{
pm.test("Checking Version" , function ()
{
pm.expect(resp.statuses[i].version).to.be.oneOf([1,2]);
});
pm.test("Checking Status" , function ()
{
pm.expect(resp.statuses[i].status).to.be.oneOf(["CCCCC","JJJJJ"]);
});
}
You can view the Chai Assertion Library to view more assertions syntax to get your work done.
1 Like
YES! I can do it! Thanks, very much.
1 Like