0
0
Postmantesting~10 mins

API versioning validation in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the API correctly handles requests for different versions. It verifies that the response matches the requested API version and returns the expected data format.

Test Code - Postman
Postman
pm.test("API version 1 returns correct response", function () {
    pm.sendRequest({
        url: pm.environment.get("baseUrl") + "/api/v1/resource",
        method: 'GET'
    }, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('status', 200);
        pm.expect(res.json()).to.have.property('version', '1');
        pm.expect(res.json()).to.have.property('data');
    });
});

pm.test("API version 2 returns correct response", function () {
    pm.sendRequest({
        url: pm.environment.get("baseUrl") + "/api/v2/resource",
        method: 'GET'
    }, function (err, res) {
        pm.expect(err).to.be.null;
        pm.expect(res).to.have.property('status', 200);
        pm.expect(res.json()).to.have.property('version', '2');
        pm.expect(res.json()).to.have.property('data');
        pm.expect(res.json().data).to.have.property('newField');
    });
});
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Send GET request to /api/v1/resourceAPI server is running and accessibleResponse status code is 200 and version field is '1'PASS
2Check response body for version '1' and presence of data fieldResponse JSON contains version and data fieldsversion == '1' and data field existsPASS
3Send GET request to /api/v2/resourceAPI server is running and accessibleResponse status code is 200 and version field is '2'PASS
4Check response body for version '2', data field, and newField inside dataResponse JSON contains version, data, and newField fieldsversion == '2' and data.newField existsPASS
Failure Scenario
Failing Condition: API returns wrong version or missing expected fields
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify when sending a request to /api/v1/resource?
AThat the response status is 404
BThat the response status is 200 and version is '1'
CThat the response contains a newField
DThat the response is empty
Key Result
Always verify that API versioning returns the correct version and expected data fields to ensure backward compatibility and proper feature support.