Consider a Postman test script that checks if the response contains exactly 10 items for page 1.
pm.test('Page 1 has 10 items', () => {
const jsonData = pm.response.json();
pm.expect(jsonData.items.length).to.eql(10);
});What will be the test result if the response has 8 items?
pm.test('Page 1 has 10 items', () => { const jsonData = pm.response.json(); pm.expect(jsonData.items.length).to.eql(10); });
Think about what happens when the expected number does not match the actual number.
The test expects exactly 10 items. If the response has 8 items, the assertion to.eql(10) fails, causing the test to fail with an assertion error.
When testing pagination in APIs, which HTTP header is typically used by clients to specify the page number or offset?
Think about headers related to partial content or ranges.
The Range header is often used to specify which part of a resource to fetch, such as a range of items for pagination.
You want to check if the JSON response contains a non-empty string field nextPageUrl indicating the next page link.
Check the correct syntax for asserting a non-empty string in Postman.
Option C correctly asserts that nextPageUrl is a string and is not empty. Option C uses invalid chaining, C assumes it's an array or string but lacks type check, D expects a boolean which is incorrect.
Given this test script:
pm.test('Check page items count', () => {
const items = pm.response.json().data.items;
pm.expect(items.length).to.eql(10);
});The test fails with TypeError: Cannot read property 'items' of undefined. What is the most likely cause?
pm.test('Check page items count', () => { const items = pm.response.json().data.items; pm.expect(items.length).to.eql(10); });
Check the path used to access the items array in the JSON response.
If the 'data' field does not exist, accessing data.items returns undefined, so items is undefined and accessing items.length causes a TypeError.
You want to write a Postman test that loops through pages 1 to 3 and asserts each page returns 10 items in the 'items' array.
Consider where to place pm.test to properly register each test with a descriptive name.
Option D correctly wraps each asynchronous response assertion inside a pm.test with a descriptive name. Option D lacks pm.test so assertions are not reported as tests. Option D incorrectly nests pm.sendRequest inside pm.test, which does not wait for async calls properly. Option D uses a valid assertion but lacks pm.test so results are not reported as separate tests.