0
0
Postmantesting~10 mins

What APIs are and why testing them matters 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 send a GET request to an API endpoint using Postman scripting.

Postman
pm.sendRequest('[1]', function (err, res) {
    pm.test('Status code is 200', function () {
        pm.expect(res.code).to.eql(200);
    });
});
Drag options to blanks, or click blank then click option'
Apm.response.to.have.status(200)
Bhttps://api.example.com/data
Cpm.expect(200).to.eql(res.code)
Dconsole.log('Hello World')
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertion code instead of the URL in pm.sendRequest
Putting console.log inside pm.sendRequest URL argument
2fill in blank
medium

Complete the code to check if the API response body contains the key 'success' set to true.

Postman
pm.test('Response has success true', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.[1]).to.eql(true);
});
Drag options to blanks, or click blank then click option'
Asuccess
Bstatus
Cerror
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' or 'error' instead of 'success' key
Trying to compare the whole response instead of the key
3fill in blank
hard

Fix the error in the assertion to correctly check the response status code is 404.

Postman
pm.test('Status code is 404', function () {
    pm.expect(pm.response.code).[1](404);
});
Drag options to blanks, or click blank then click option'
Ato.eql
Bto.equal
Cto.be.eql
Dto.be.equal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to.equal' which is not valid in this context
Adding extra 'be' causing syntax errors
4fill in blank
hard

Fill both blanks to create a test that checks the response time is less than 200 milliseconds.

Postman
pm.test('Response time is fast', function () {
    pm.expect(pm.response.[1]).to.be.[2](200);
});
Drag options to blanks, or click blank then click option'
AresponseTime
Bstatus
Cbelow
Dabove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'responseTime' for the property
Using 'above' instead of 'below' for the assertion
5fill in blank
hard

Fill all three blanks to write a test that verifies the response JSON has a 'data' array with length greater than 0.

Postman
pm.test('Data array is not empty', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.[1]).to.be.an('array').that.[2].length.[3](0);
});
Drag options to blanks, or click blank then click option'
Adata
Bhas
Cabove
Dincludes
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'includes' instead of 'has' for property assertion
Using 'below' instead of 'above' for length check