0
0
Postmantesting~10 mins

Schema validation basics 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 validate 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'
A404
B200
C500
D201
Attempts:
3 left
💡 Hint
Common Mistakes
Using 201 which means created, not OK.
Using 404 which means not found.
Using 500 which means server error.
2fill in blank
medium

Complete the code to check if the JSON response has a property named 'userId'.

Postman
pm.test('Response has userId', function () { pm.expect(pm.response.json()).to.have.property([1]); });
Drag options to blanks, or click blank then click option'
A'name'
B'id'
C'userId'
D'email'
Attempts:
3 left
💡 Hint
Common Mistakes
Using property names that do not exist in the response.
Forgetting to put quotes around the property name.
3fill in blank
hard

Fix the error in the code to correctly validate the response JSON schema.

Postman
const schema = [1];
pm.test('Schema is valid', function () { pm.response.to.have.jsonSchema(schema); });
Drag options to blanks, or click blank then click option'
Anull
B'{ type: object, properties: { id: { type: number } }, required: [id] }'
C42
D{ type: 'object', properties: { id: { type: 'number' } }, required: ['id'] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an object for the schema.
Using null or numbers instead of a schema object.
4fill in blank
hard

Fill both blanks to check that the response JSON has a 'name' property of type string.

Postman
const schema = { type: 'object', properties: { name: { type: [1] } }, required: [[2]] };
pm.test('Name property is string', function () { pm.response.to.have.jsonSchema(schema); });
Drag options to blanks, or click blank then click option'
A'string'
B'name'
C'number'
D'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'number' instead of 'string' for the type.
Forgetting to put quotes around the required property name.
5fill in blank
hard

Fill all three blanks to validate a response JSON with 'id' as number, 'email' as string, and both required.

Postman
const schema = {
  type: 'object',
  properties: {
    id: { type: [1] },
    email: { type: [2] }
  },
  required: [[3]]
};
pm.test('Validate id and email', function () {
  pm.response.to.have.jsonSchema(schema);
});
Drag options to blanks, or click blank then click option'
A'number'
B'string'
C'id', 'email'
D'email'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the required properties without quotes or as separate strings.
Mixing up the types for id and email.