0
0
Postmantesting~5 mins

Response body array assertions in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a response body array assertion in API testing?
It is a check to confirm that the response from an API contains an array and that this array meets certain conditions like length, content, or structure.
Click to reveal answer
beginner
How do you check if the response body contains an array with at least 3 items in Postman?
Use the assertion: pm.expect(pm.response.json()).to.be.an('array').with.lengthOf.at.least(3);
Click to reveal answer
intermediate
Why is it important to assert the type of response body elements in an array?
To ensure the API returns data in the expected format, which helps avoid errors in later processing or display of data.
Click to reveal answer
intermediate
Show how to assert that every item in a response array has a property 'id' in Postman.
Use: pm.response.json().forEach(item => pm.expect(item).to.have.property('id'));
Click to reveal answer
intermediate
What does the assertion pm.expect(pm.response.json()).to.include.members([1, 2]) check in a response array?
It checks that the response array includes the members 1 and 2 somewhere in its elements.
Click to reveal answer
Which Postman assertion checks if the response body is an array?
Apm.expect(pm.response.code).to.equal(200);
Bpm.expect(pm.response.text()).to.be.a('string');
Cpm.expect(pm.response.json()).to.have.property('length');
Dpm.expect(pm.response.json()).to.be.an('array');
How do you assert that every object in a response array has a 'name' property?
Apm.response.json().forEach(item => pm.expect(item).to.have.property('name'));
Bpm.expect(pm.response.json()).to.include('name');
Cpm.expect(pm.response.json()).to.have.property('name');
Dpm.expect(pm.response.json()).to.be.an('array');
What does this assertion check? pm.expect(pm.response.json()).to.have.lengthOf(5);
AResponse array has exactly 5 items.
BResponse array has at least 5 items.
CResponse array has no more than 5 items.
DResponse array is empty.
Which assertion verifies that the response array includes the number 10?
Apm.expect(pm.response.json()).to.include(10);
Bpm.expect(pm.response.json()).to.include.members([10]);
Cpm.expect(pm.response.json()).to.have.property(10);
Dpm.expect(pm.response.json()).to.be.an('array');
Why should you assert the response array structure in API testing?
ATo speed up the API response time.
BTo change the API response data.
CTo confirm the API returns data in the expected format.
DTo ignore errors in the response.
Explain how to write assertions in Postman to verify that a response body contains an array with specific properties in each item.
Think about using pm.response.json(), array methods, and pm.expect() assertions.
You got /4 concepts.
    Describe why it is important to assert the length and content of an array in an API response.
    Consider what happens if the array is empty or missing expected elements.
    You got /4 concepts.