0
0
Postmantesting~10 mins

Query parameters in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request with query parameters to an API endpoint and verifies that the response contains the expected filtered data based on those parameters.

Test Code - Postman
Postman
pm.test("Verify response contains correct query parameter data", function () {
    const url = pm.request.url;
    pm.expect(url.getQueryString()).to.include("status=active");

    pm.response.to.have.status(200);
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.be.an('array');
    jsonData.forEach(item => {
        pm.expect(item.status).to.eql('active');
    });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and prepares GET request with query parameter 'status=active'Postman UI shows request URL with '?status=active' appended-PASS
2Sends GET request to API endpoint with query parameterRequest sent to server with URL including '?status=active'-PASS
3Receives response with HTTP status 200 and JSON bodyResponse body contains array of objects with 'status' fieldspm.response.to.have.status(200)PASS
4Checks that request URL contains query parameter 'status=active'URL query string is 'status=active'pm.expect(url.getQueryString()).to.include("status=active")PASS
5Verifies each item in response array has 'status' equal to 'active'All items in JSON array have 'status' field with value 'active'pm.expect(item.status).to.eql('active') for each itemPASS
Failure Scenario
Failing Condition: Response does not contain expected query parameter or data filtered by it
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the request URL?
AIt contains the query parameter 'status=active'
BIt uses POST method
CIt has no query parameters
DIt contains a header named 'status'
Key Result
Always verify that query parameters are correctly included in the request URL and that the API response respects those parameters by filtering data accordingly.