Bird
Raised Fist0
Postmantesting~20 mins

Testing pagination in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pagination Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the result of this Postman test script for pagination?

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?

Postman
pm.test('Page 1 has 10 items', () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.items.length).to.eql(10);
});
ATest fails with assertion error
BTest passes successfully
CTest throws a syntax error
DTest is skipped automatically
Attempts:
2 left
💡 Hint

Think about what happens when the expected number does not match the actual number.

🧠 Conceptual
intermediate
1:30remaining
Which HTTP header is commonly used to control pagination in API requests?

When testing pagination in APIs, which HTTP header is typically used by clients to specify the page number or offset?

AContent-Type
BRange
CAccept
DAuthorization
Attempts:
2 left
💡 Hint

Think about headers related to partial content or ranges.

❓ assertion
advanced
2:00remaining
Which Postman test assertion correctly verifies the presence of a 'next' page link in pagination?

You want to check if the JSON response contains a non-empty string field nextPageUrl indicating the next page link.

Apm.expect(pm.response.json().nextPageUrl).to.be.true;
Bpm.expect(pm.response.json().nextPageUrl).to.exist.and.not.empty();
Cpm.expect(pm.response.json().nextPageUrl).to.be.a('string').and.not.empty;
Dpm.expect(pm.response.json().nextPageUrl).to.have.length.above(0);
Attempts:
2 left
💡 Hint

Check the correct syntax for asserting a non-empty string in Postman.

🔧 Debug
advanced
2:00remaining
Why does this Postman pagination test script fail with a TypeError?

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?

Postman
pm.test('Check page items count', () => {
  const items = pm.response.json().data.items;
  pm.expect(items.length).to.eql(10);
});
AThe response JSON does not have a 'data' field
BThe 'items' field is null instead of an array
CThe 'items' field is an empty array
DThe pm.expect syntax is incorrect
Attempts:
2 left
💡 Hint

Check the path used to access the items array in the JSON response.

❓ framework
expert
3:00remaining
Which Postman test script snippet correctly tests that all pages of a paginated API return exactly 10 items?

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.

A
for(let page=1; page<=3; page++) {
  pm.sendRequest({url: `https://api.example.com/data?page=${page}`}, (err, res) => {
    pm.expect(res.json().items).to.have.lengthOf(10);
  });
}
B
for(let page=1; page<=3; page++) {
  pm.sendRequest({url: `https://api.example.com/data?page=${page}`}, (err, res) => {
    pm.expect(res.json().items.length).to.eql(10);
  });
}
C
for(let page=1; page<=3; page++) {
  pm.test(`Page ${page} has 10 items`, () => {
    pm.sendRequest({url: `https://api.example.com/data?page=${page}`}, (err, res) => {
      pm.expect(res.json().items.length).to.eql(10);
    });
  });
}
D
for(let page=1; page<=3; page++) {
  pm.sendRequest({url: `https://api.example.com/data?page=${page}`}, (err, res) => {
    pm.test(`Page ${page} has 10 items`, () => {
      pm.expect(res.json().items.length).to.eql(10);
    });
  });
}
Attempts:
2 left
💡 Hint

Consider where to place pm.test to properly register each test with a descriptive name.

Practice

(1/5)
1. What is the main purpose of testing pagination in an API using Postman?
easy
A. To verify that users can navigate through pages and see correct data counts
B. To check if the API returns data in alphabetical order
C. To ensure the API response time is under 1 second
D. To test if the API supports multiple languages

Solution

  1. Step 1: Understand pagination purpose

    Pagination testing ensures users can move through pages and see correct data on each page.
  2. Step 2: Identify key verification points

    We check page numbers, item counts, and total items to confirm correct navigation.
  3. Final Answer:

    To verify that users can navigate through pages and see correct data counts -> Option A
  4. Quick Check:

    Pagination = navigation + correct data [OK]
Hint: Pagination tests check page navigation and item counts [OK]
Common Mistakes:
  • Confusing pagination with sorting
  • Focusing only on response time
  • Ignoring total item count
2. Which Postman script snippet correctly checks if the current page number is 3 in the response JSON?
easy
A. pm.test('Page is 3', () => pm.expect(pm.response.page).to.eql(3));
B. pm.test('Page is 3', () => pm.expect(response.page).to.equal(3));
C. pm.test('Page is 3', () => pm.expect(pm.response.json().page).to.eql(3));
D. pm.test('Page is 3', () => pm.expect(json.page).to.eql(3));

Solution

  1. Step 1: Access response JSON correctly

    Use pm.response.json() to parse the response body as JSON.
  2. Step 2: Use correct assertion syntax

    pm.expect(...).to.eql(3) checks if the page value equals 3.
  3. Final Answer:

    pm.test('Page is 3', () => pm.expect(pm.response.json().page).to.eql(3)); -> Option C
  4. Quick Check:

    Use pm.response.json() + pm.expect() [OK]
Hint: Use pm.response.json() to parse JSON before assertions [OK]
Common Mistakes:
  • Using undefined variables like response or json
  • Accessing pm.response.page directly
  • Using to.equal instead of to.eql in Postman
3. Given this Postman test script, what will be the test result if the response JSON is {"page":2,"per_page":5,"total":12,"data":[1,2,3,4,5]}?
pm.test('Check page and items', () => {
  const json = pm.response.json();
  pm.expect(json.page).to.eql(2);
  pm.expect(json.data.length).to.eql(json.per_page);
  pm.expect(json.total).to.be.above(10);
});
medium
A. Test fails because page is not 2
B. Test fails because total is not above 10
C. Test fails because data length does not match per_page
D. All tests pass

Solution

  1. Step 1: Check page number assertion

    json.page is 2, expected 2, so this passes.
  2. Step 2: Check data length equals per_page

    json.data.length is 5, json.per_page is 5, so this passes.
  3. Step 3: Check total is above 10

    json.total is 12, which is above 10, so this passes.
  4. Final Answer:

    All tests pass -> Option D
  5. Quick Check:

    All assertions true = pass [OK]
Hint: Match data length with per_page and check total > 10 [OK]
Common Mistakes:
  • Assuming total must equal per_page
  • Confusing page number with index
  • Ignoring data array length
4. You wrote this Postman test to check pagination but it always fails:
pm.test('Page is 1', () => {
  const json = pm.response.json();
  pm.expect(json.page).to.equal(1);
});
The response JSON is {"page":1,"per_page":10,"total":50}. What is the likely error?
medium
A. The assertion syntax is correct; failure is due to response mismatch
B. Using to.equal instead of to.eql causes failure
C. pm.response.json() is not called correctly
D. The response JSON does not contain page key

Solution

  1. Step 1: Check assertion method

    to.equal and to.eql behave similarly for primitives; this is not the cause.
  2. Step 2: Verify response JSON keys

    Response has page key with value 1, so JSON access is correct.
  3. Step 3: Consider response mismatch

    If test fails, likely the actual response page value differs or test runs on wrong response.
  4. Final Answer:

    The assertion syntax is correct; failure is due to response mismatch -> Option A
  5. Quick Check:

    Assertion syntax correct; check response data [OK]
Hint: Check actual response data if assertion syntax looks correct [OK]
Common Mistakes:
  • Confusing to.equal and to.eql for primitives
  • Assuming JSON parsing failed
  • Ignoring actual response content
5. You want to test that the API correctly handles the last page of pagination when total items are 23 and per_page is 5. Which Postman test script correctly verifies the last page number and item count on that page?
hard
A. pm.test('Last page check', () => { const json = pm.response.json(); pm.expect(json.page).to.eql(json.total); pm.expect(json.data.length).to.eql(json.per_page); });
B. pm.test('Last page check', () => { const json = pm.response.json(); const lastPage = Math.ceil(json.total / json.per_page); pm.expect(json.page).to.eql(lastPage); pm.expect(json.data.length).to.eql(json.total % json.per_page || json.per_page); });
C. pm.test('Last page check', () => { const json = pm.response.json(); pm.expect(json.page).to.eql(json.total % json.per_page); pm.expect(json.data.length).to.eql(json.per_page); });
D. pm.test('Last page check', () => { const json = pm.response.json(); pm.expect(json.page).to.eql(json.total / json.per_page); pm.expect(json.data.length).to.eql(json.per_page); });

Solution

  1. Step 1: Calculate last page number

    Last page = ceiling of total / per_page = ceil(23/5) = 5.
  2. Step 2: Calculate expected items on last page

    Items on last page = total % per_page = 23 % 5 = 3 (if 0, use per_page).
  3. Step 3: Verify page number and data length

    Check json.page equals lastPage and json.data.length equals expected items.
  4. Final Answer:

    pm.test('Last page check', () => { const json = pm.response.json(); const lastPage = Math.ceil(json.total / json.per_page); pm.expect(json.page).to.eql(lastPage); pm.expect(json.data.length).to.eql(json.total % json.per_page || json.per_page); }); -> Option B
  5. Quick Check:

    Last page = ceil(total/per_page), items = remainder or per_page [OK]
Hint: Use Math.ceil for last page and remainder for last page items [OK]
Common Mistakes:
  • Using division without ceiling for last page
  • Expecting full per_page items on last page always
  • Confusing modulo result with page number
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard