0
0
Postmantesting~5 mins

Testing pagination in Postman

Choose your learning style9 modes available
Introduction

Testing pagination helps ensure that data is split correctly across pages. It checks that users can see all items without missing or repeating any.

When an API returns a large list of items split into pages.
When you want to verify the 'next' and 'previous' page links work correctly.
When checking that the number of items per page matches the expected limit.
When validating that the last page shows the remaining items correctly.
When ensuring no duplicate or missing items appear across pages.
Syntax
Postman
GET /items?page=1&limit=10

Use query parameters like page and limit to control pagination.

Check response fields for total items, current page, and links to next/previous pages.

Examples
Request the second page with 5 items per page.
Postman
GET /products?page=2&limit=5
Request the first page with 20 users per page.
Postman
GET /users?page=1&limit=20
Sample Program

This Postman test script checks that the pagination response has the correct current page, the number of items does not exceed the limit, total items is positive, and the next page link is present if there are more pages.

Postman
// Postman test script to check pagination

// Parse JSON response
const response = pm.response.json();

// Check current page is 1
pm.test('Current page is 1', () => {
    pm.expect(response.page).to.eql(1);
});

// Check number of items returned is less or equal to limit
pm.test('Items count is correct', () => {
    pm.expect(response.items.length).to.be.at.most(10);
});

// Check total items is a positive number
pm.test('Total items is positive', () => {
    pm.expect(response.total).to.be.above(0);
});

// Check next page link exists if more pages
pm.test('Next page link exists if not last page', () => {
    if (response.page * response.limit < response.total) {
        pm.expect(response.next).to.be.a('string').and.not.empty;
    } else {
        pm.expect(response.next).to.be.null;
    }
});
OutputSuccess
Important Notes

Always check both the data and the pagination metadata in the response.

Test edge cases like the first page, last page, and pages beyond the last.

Use Postman environment variables to automate testing multiple pages.

Summary

Pagination testing ensures users can navigate through data pages correctly.

Check page number, item count, total items, and navigation links.

Use Postman scripts to automate and validate pagination behavior.