Verify Pretty, Raw, and Preview response views in Postman
Preconditions (2)
✅ Expected Result: The Pretty view shows formatted and color-coded JSON, the Raw view shows plain text JSON, and the Preview view renders the response appropriately.
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response body is valid JSON', () => { pm.expect(() => pm.response.json()).not.to.throw(); }); pm.test('Raw response matches response text', () => { const rawText = pm.response.text(); pm.expect(rawText).to.be.a('string').and.not.empty; }); pm.test('Content-Type header is present for preview', () => { pm.response.to.have.header('Content-Type'); const contentType = pm.response.headers.get('Content-Type'); pm.expect(contentType).to.match(/application\/json|text\//); });
The first test checks the HTTP status code is 200, confirming the request succeeded.
The second test tries to parse the response body as JSON to simulate the Pretty view, which formats JSON.
The third test verifies the raw response text is a non-empty string, simulating the Raw view showing plain text.
The fourth test checks the Content-Type header to ensure the Preview view can render the response correctly.
These tests use Postman's pm API for clear, maintainable assertions.
Now add data-driven testing with 3 different API endpoints to verify Pretty, Raw, and Preview views for each.
Pass the test and this pattern moves unknown