Verify API access with Basic Authentication
Preconditions (3)
✅ Expected Result: The API responds with status code 200 and returns the expected data in JSON format
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response has expected data', () => { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('data'); pm.expect(jsonData.data).to.be.an('array'); });
The first test checks that the API response status code is 200, which means the request was successful.
The second test parses the response body as JSON and verifies it contains a property named 'data' which should be an array. This confirms the API returned the expected data structure.
Using pm.response.to.have.status and pm.expect are Postman's recommended ways to write assertions in test scripts.
Environment variables for username and password help keep credentials secure and reusable.
Now add data-driven testing with 3 different username and password combinations