0
0
Postmantesting~15 mins

Raw body (text, XML) in Postman - Build an Automation Script

Choose your learning style9 modes available
Send POST request with raw XML body and verify response
Preconditions (2)
Step 1: Open Postman and create a new POST request
Step 2: Set the request URL to https://api.example.com/orders
Step 3: Go to the Body tab and select 'raw' option
Step 4: Select 'XML' from the dropdown next to raw
Step 5: Enter the following XML content in the body:<order><id>123</id><item>Book</item><quantity>2</quantity></order>
Step 6: Click Send button
Step 7: Observe the response status code and body
✅ Expected Result: Response status code is 200 OK and response body contains confirmation message with order id 123
Automation Requirements - Postman/Newman
Assertions Needed:
Verify response status code is 200
Verify response body contains order id 123 confirmation
Best Practices:
Use raw body with correct Content-Type header set to application/xml
Use test scripts in Postman to assert response
Keep XML body well-formed and valid
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

pm.test('Response contains order id 123', function () {
    const responseBody = pm.response.text();
    pm.expect(responseBody).to.include('<id>123</id>');
});

The first test checks that the response status code is exactly 200, which means the request was successful.

The second test reads the response body as text and verifies it contains the XML tag with order id 123, confirming the order was processed.

Using pm.response.to.have.status(200) is the standard way in Postman to assert status codes.

Checking the raw response text for the expected XML snippet ensures the server returned the correct data.

Common Mistakes - 3 Pitfalls
Not setting Content-Type header to application/xml
Using JSON body format instead of XML when API expects XML
Not validating response status code before checking body
Bonus Challenge

Now add data-driven testing with 3 different XML orders having different ids and items

Show Hint