0
0
Postmantesting~10 mins

Testing pagination in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the API pagination works correctly by requesting the first page of results and verifying the response contains the expected number of items and pagination metadata.

Test Code - Postman
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Response has pagination info", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('page');
    pm.expect(jsonData).to.have.property('per_page');
    pm.expect(jsonData).to.have.property('total');
    pm.expect(jsonData).to.have.property('total_pages');
});

pm.test("Response data length matches per_page", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.data.length).to.eql(jsonData.per_page);
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send GET request to API endpoint with page=1 parameterAPI server receives request and processes pagination parameters-PASS
2Check response status code is 200Response received with status 200 OKpm.response.to.have.status(200)PASS
3Parse JSON response and verify pagination properties existResponse JSON contains keys: page, per_page, total, total_pagespm.expect(jsonData).to.have.property('page') and othersPASS
4Verify the length of data array equals per_page valueData array length matches per_page countpm.expect(jsonData.data.length).to.eql(jsonData.per_page)PASS
Failure Scenario
Failing Condition: API returns fewer items than per_page or missing pagination fields
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first after sending the request?
AResponse contains user details
BResponse data length matches total
CResponse status code is 200
DResponse time is less than 1 second
Key Result
Always verify both the pagination metadata and the actual data count to ensure the API returns consistent and correct paged results.