0
0
Postmantesting~10 mins

Response body assertions in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the response status is 200.

Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status([1]);
});
Drag options to blanks, or click blank then click option'
A500
B404
C201
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong status code like 404 or 500.
Using a string instead of a number.
2fill in blank
medium

Complete the code to assert that the response body contains the string 'success'.

Postman
pm.test("Body contains success", function () {
    pm.expect(pm.response.text()).to.include([1]);
});
Drag options to blanks, or click blank then click option'
A"error"
B"success"
C"fail"
D"pending"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a word that is not in the response body.
Forgetting the quotes around the string.
3fill in blank
hard

Fix the error in the code to correctly assert that the JSON response has a property 'id'.

Postman
pm.test("Response has id", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property([1]);
});
Drag options to blanks, or click blank then click option'
A"id"
B'jsonData.id'
CjsonData.id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using the property name without quotes.
Using the value of the property instead of the name.
4fill in blank
hard

Fill both blanks to assert that the response JSON has a property 'name' and its value equals 'John'.

Postman
pm.test("Name is John", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property([1], [2]);
});
Drag options to blanks, or click blank then click option'
A"name"
B"John"
C'John'
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using property name without quotes.
Using value without quotes or wrong quotes.
5fill in blank
hard

Fill all three blanks to assert that the response JSON array 'users' has length greater than 0 and the first user's 'active' property is true.

Postman
pm.test("Users array is not empty and first user is active", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.[1]).to.be.an('array').that.has.length.[2](0);
    pm.expect(jsonData.users[0].[3]).to.be.true;
});
Drag options to blanks, or click blank then click option'
Ausers
Babove
Cactive
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'length' instead of 'users' for the array.
Using 'length' instead of 'above' for the length check.
Checking wrong property name instead of 'active'.