0
0
Postmantesting~20 mins

Testing pagination in Postman - Practice Problems & Coding Challenges

Choose your learning style9 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.