0
0
Postmantesting~10 mins

JSON value 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 code 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'
A200
B500
C404
D201
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong status code like 201 or 404.
Forgetting to put the status code as a number.
2fill in blank
medium

Complete the code to assert that the JSON response has a key named 'name'.

Postman
pm.test("Response has 'name' key", function () { pm.expect(pm.response.json()).to.have.property([1]); });
Drag options to blanks, or click blank then click option'
A"age"
B"name"
C"email"
D"status"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong key name.
Not using quotes around the key.
3fill in blank
hard

Fix the error in the code to assert that the 'age' value equals 30.

Postman
pm.test("Age is 30", function () { pm.expect(pm.response.json().age).to.be.[1](30); });
Drag options to blanks, or click blank then click option'
Aequals
Beq
Cequal
DequalTo
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'equals' or 'eq' which cause errors.
Misspelling the method name.
4fill in blank
hard

Fill both blanks to assert that the response JSON array 'users' has length 5.

Postman
pm.test("Users array length is 5", function () { pm.expect(pm.response.json().[1]).to.have.length[2](5); });
Drag options to blanks, or click blank then click option'
Ausers
BlengthOf
Clength
DuserList
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key name like 'userList'.
Using 'length' instead of 'lengthOf' in assertion.
5fill in blank
hard

Fill all three blanks to assert that the 'status' key in JSON equals 'success' and is a string.

Postman
pm.test("Status is success string", function () { pm.expect(pm.response.json().[1]).to.be.a([2]).and.to.equal([3]); });
Drag options to blanks, or click blank then click option'
Astatus
B"string"
C"success"
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key name like 'result'.
Not quoting the type or value strings.