Given this Postman test script that checks the API version in response headers, what will be the test result?
pm.test('API version is 2.0', () => { pm.response.to.have.header('X-API-Version'); pm.expect(pm.response.headers.get('X-API-Version')).to.eql('2.0'); });
Check how the test asserts the header value exactly equals '2.0'.
The test first checks the header exists, then asserts its value equals '2.0'. If the header is missing or value differs, the test fails.
You receive this JSON response: {"version": "v1.3"}. Which Postman assertion correctly checks the version is 'v1.3'?
Remember the version is a string, so the assertion must compare string values.
Option B correctly compares the string value 'v1.3'. Option B compares to a number, which is wrong. Option B uses invalid syntax. Option B wrongly treats the version as an object.
Test code:
pm.test('API version in URL is v2', () => {
const url = pm.request.url.toString();
pm.expect(url.includes('/v2/')).to.be.true;
});But the test fails even though the URL is https://api.example.com/v2users. Why?
Check the exact substring searched and the actual URL string.
The URL is 'https://api.example.com/v2users' which contains '/v2' but not '/v2/' exactly. The includes('/v2/') check fails because of the trailing slash in the search string.
Choose the script that checks the response header 'X-API-Version' equals '1.0' and the JSON body field 'apiVersion' equals '1.0' in one test.
Check correct header access method and matching string types.
Option C uses pm.response.headers.get() correctly and compares strings with to.eql(). Option C uses invalid header assertion syntax and compares string to number. Option C incorrectly accesses headers as object. Option C compares string header to number 1.0.
Which statement best describes a robust approach to validate API versioning in automated API tests?
Think about how to catch version mismatches effectively.
Validating both headers and body ensures the API version is consistent across all parts of the response. Relying on only one source risks missing discrepancies. Skipping validation or checking only URL is insufficient for robust testing.