0
0
Postmantesting~15 mins

Pretty, raw, and preview views in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify Pretty, Raw, and Preview response views in Postman
Preconditions (2)
Step 1: Open Postman and create a new GET request
Step 2: Enter the URL https://jsonplaceholder.typicode.com/posts/1
Step 3: Click the Send button
Step 4: Observe the response section
Step 5: Click the Pretty tab and verify the response is formatted and color-coded
Step 6: Click the Raw tab and verify the response is shown as plain text without formatting
Step 7: Click the Preview tab and verify the response is rendered as a web preview (HTML or JSON rendered)
✅ 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.
Automation Requirements - Postman test scripts
Assertions Needed:
Response status code is 200
Response body is valid JSON
Pretty view shows formatted JSON (simulated by checking JSON parse success)
Raw view matches the exact response text
Preview view renders content-type correctly (simulate by checking headers)
Best Practices:
Use pm.response API for assertions
Validate response status and body before checking views
Avoid hardcoding response text; use dynamic checks
Keep tests independent and clear
Automated Solution
Postman
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.

Common Mistakes - 3 Pitfalls
Not checking the response status code before parsing JSON
Hardcoding expected raw response text
Ignoring Content-Type header when verifying preview
Bonus Challenge

Now add data-driven testing with 3 different API endpoints to verify Pretty, Raw, and Preview views for each.

Show Hint