How to check whether one node in API response has same value under all object using postman tests?










2















Suppose a API request fetches a users id, email address and their designated role. Sample API Request below:



GET: /v1/users HTTP/1.1
Content-Type: application/json
Authorization: bearer access_token


For the above request, the following is the response:




"content": [

"id": 1,
"email": "random@random.com",
"full_name": "AlbusDumbledore",
"role": "OWNER"
,

"id": 40,
"email": "random1@random1.com",
"role": "OWNER"

],
"last": false,
"total_elements": 2,
"total_pages": 1,
"sort": null,
"first": true,
"number_of_elements": 2,
"size": 20,
"number": 0



Now, what will be the test in postman to make sure that all the returned values under role node is equal to OWNER?










share|improve this question






















  • can you run javascript in postman?

    – Jaromanda X
    Jan 17 '18 at 8:09















2















Suppose a API request fetches a users id, email address and their designated role. Sample API Request below:



GET: /v1/users HTTP/1.1
Content-Type: application/json
Authorization: bearer access_token


For the above request, the following is the response:




"content": [

"id": 1,
"email": "random@random.com",
"full_name": "AlbusDumbledore",
"role": "OWNER"
,

"id": 40,
"email": "random1@random1.com",
"role": "OWNER"

],
"last": false,
"total_elements": 2,
"total_pages": 1,
"sort": null,
"first": true,
"number_of_elements": 2,
"size": 20,
"number": 0



Now, what will be the test in postman to make sure that all the returned values under role node is equal to OWNER?










share|improve this question






















  • can you run javascript in postman?

    – Jaromanda X
    Jan 17 '18 at 8:09













2












2








2


1






Suppose a API request fetches a users id, email address and their designated role. Sample API Request below:



GET: /v1/users HTTP/1.1
Content-Type: application/json
Authorization: bearer access_token


For the above request, the following is the response:




"content": [

"id": 1,
"email": "random@random.com",
"full_name": "AlbusDumbledore",
"role": "OWNER"
,

"id": 40,
"email": "random1@random1.com",
"role": "OWNER"

],
"last": false,
"total_elements": 2,
"total_pages": 1,
"sort": null,
"first": true,
"number_of_elements": 2,
"size": 20,
"number": 0



Now, what will be the test in postman to make sure that all the returned values under role node is equal to OWNER?










share|improve this question














Suppose a API request fetches a users id, email address and their designated role. Sample API Request below:



GET: /v1/users HTTP/1.1
Content-Type: application/json
Authorization: bearer access_token


For the above request, the following is the response:




"content": [

"id": 1,
"email": "random@random.com",
"full_name": "AlbusDumbledore",
"role": "OWNER"
,

"id": 40,
"email": "random1@random1.com",
"role": "OWNER"

],
"last": false,
"total_elements": 2,
"total_pages": 1,
"sort": null,
"first": true,
"number_of_elements": 2,
"size": 20,
"number": 0



Now, what will be the test in postman to make sure that all the returned values under role node is equal to OWNER?







javascript testing postman functional-testing qa






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 17 '18 at 8:06









Noor Yeaser KhanNoor Yeaser Khan

467




467












  • can you run javascript in postman?

    – Jaromanda X
    Jan 17 '18 at 8:09

















  • can you run javascript in postman?

    – Jaromanda X
    Jan 17 '18 at 8:09
















can you run javascript in postman?

– Jaromanda X
Jan 17 '18 at 8:09





can you run javascript in postman?

– Jaromanda X
Jan 17 '18 at 8:09












1 Answer
1






active

oldest

votes


















3














You could add something like a loop to check for it?



pm.test("Check role equals OWNER", () => 
var jsonData = pm.response.json()
for (i = 0; i < jsonData.content.length; i++)
pm.expect(jsonData.content[i].role).to.equal('OWNER')

)


This should work to check the value of each role property, if the schema response you posted is correct.



I changed one of the values and ran the test again to show you it working - This will show the failure in Postman if the property is not equal to 'OWNER'.



enter image description here






share|improve this answer

























  • Thanks a lot Danny! It worked perfectly.

    – Noor Yeaser Khan
    Jan 17 '18 at 9:40











  • No worries! It's very basic but it'll do the check.

    – Danny Dainton
    Jan 17 '18 at 9:45










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48296284%2fhow-to-check-whether-one-node-in-api-response-has-same-value-under-all-object-us%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You could add something like a loop to check for it?



pm.test("Check role equals OWNER", () => 
var jsonData = pm.response.json()
for (i = 0; i < jsonData.content.length; i++)
pm.expect(jsonData.content[i].role).to.equal('OWNER')

)


This should work to check the value of each role property, if the schema response you posted is correct.



I changed one of the values and ran the test again to show you it working - This will show the failure in Postman if the property is not equal to 'OWNER'.



enter image description here






share|improve this answer

























  • Thanks a lot Danny! It worked perfectly.

    – Noor Yeaser Khan
    Jan 17 '18 at 9:40











  • No worries! It's very basic but it'll do the check.

    – Danny Dainton
    Jan 17 '18 at 9:45















3














You could add something like a loop to check for it?



pm.test("Check role equals OWNER", () => 
var jsonData = pm.response.json()
for (i = 0; i < jsonData.content.length; i++)
pm.expect(jsonData.content[i].role).to.equal('OWNER')

)


This should work to check the value of each role property, if the schema response you posted is correct.



I changed one of the values and ran the test again to show you it working - This will show the failure in Postman if the property is not equal to 'OWNER'.



enter image description here






share|improve this answer

























  • Thanks a lot Danny! It worked perfectly.

    – Noor Yeaser Khan
    Jan 17 '18 at 9:40











  • No worries! It's very basic but it'll do the check.

    – Danny Dainton
    Jan 17 '18 at 9:45













3












3








3







You could add something like a loop to check for it?



pm.test("Check role equals OWNER", () => 
var jsonData = pm.response.json()
for (i = 0; i < jsonData.content.length; i++)
pm.expect(jsonData.content[i].role).to.equal('OWNER')

)


This should work to check the value of each role property, if the schema response you posted is correct.



I changed one of the values and ran the test again to show you it working - This will show the failure in Postman if the property is not equal to 'OWNER'.



enter image description here






share|improve this answer















You could add something like a loop to check for it?



pm.test("Check role equals OWNER", () => 
var jsonData = pm.response.json()
for (i = 0; i < jsonData.content.length; i++)
pm.expect(jsonData.content[i].role).to.equal('OWNER')

)


This should work to check the value of each role property, if the schema response you posted is correct.



I changed one of the values and ran the test again to show you it working - This will show the failure in Postman if the property is not equal to 'OWNER'.



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 17 '18 at 9:09

























answered Jan 17 '18 at 8:18









Danny DaintonDanny Dainton

4,44121021




4,44121021












  • Thanks a lot Danny! It worked perfectly.

    – Noor Yeaser Khan
    Jan 17 '18 at 9:40











  • No worries! It's very basic but it'll do the check.

    – Danny Dainton
    Jan 17 '18 at 9:45

















  • Thanks a lot Danny! It worked perfectly.

    – Noor Yeaser Khan
    Jan 17 '18 at 9:40











  • No worries! It's very basic but it'll do the check.

    – Danny Dainton
    Jan 17 '18 at 9:45
















Thanks a lot Danny! It worked perfectly.

– Noor Yeaser Khan
Jan 17 '18 at 9:40





Thanks a lot Danny! It worked perfectly.

– Noor Yeaser Khan
Jan 17 '18 at 9:40













No worries! It's very basic but it'll do the check.

– Danny Dainton
Jan 17 '18 at 9:45





No worries! It's very basic but it'll do the check.

– Danny Dainton
Jan 17 '18 at 9:45



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48296284%2fhow-to-check-whether-one-node-in-api-response-has-same-value-under-all-object-us%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20