Verify API response with query parameters
Preconditions (2)
✅ Expected Result: Response status code is 200 OK and response body contains a list of 5 items all belonging to category 'books'
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response body is an array of 5 items', () => { const jsonData = pm.response.json(); pm.expect(jsonData).to.be.an('array', 'Response is not an array'); pm.expect(jsonData.length).to.eql(5, 'Response array length is not 5'); }); pm.test('All items have category "books"', () => { const jsonData = pm.response.json(); jsonData.forEach(item => { pm.expect(item.category).to.eql('books', `Item category is not 'books': ${JSON.stringify(item)}`); }); });
The first test checks that the response status code is 200, confirming the request was successful.
The second test parses the response body as JSON and verifies it is an array with exactly 5 items, matching the 'limit' query parameter.
The third test loops through each item in the response array and asserts that the 'category' field equals 'books', matching the 'category' query parameter.
Using descriptive messages helps identify which assertion failed if the test does not pass.
Now add data-driven testing with 3 different sets of query parameters: category=books & limit=5, category=electronics & limit=3, category=clothing & limit=4
user and id with values alice and 123 respectively in Postman?user=alice&id=123 is correct.https://api.example.com/data?type=fruit&color=red, what will Postman send as query parameters?type=fruit and color=red.https://api.example.com/search?query=books&limit10 in Postman. What is wrong with this query parameter syntax?Pass the test and this pattern moves unknown