0
0
Postmantesting~20 mins

Raw body (text, XML) in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Raw XML Body Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script?
You send a POST request with raw XML body:
<note>
  <to>Alice</to>
  <from>Bob</from>
  <message>Hello</message>
</note>

In the Tests tab, you run this script:
const xml = pm.request.body.raw;
pm.test('Contains <to> tag', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});

What will be the test result?
Postman
const xml = pm.request.body.raw;
pm.test('Contains <to> tag', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});
ATest fails because the XML tags are case-sensitive and '<to>' is lowercase.
BTest fails because pm.request.body.raw is undefined in Postman scripts.
CTest passes because the raw XML contains the exact string '<to>Alice</to>'.
DTest throws a syntax error due to incorrect use of pm.expect.
Attempts:
2 left
💡 Hint
pm.request.body.raw contains the raw request body as a string.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the raw XML body contains the tag with 'Hello'?
You want to check that the raw XML body sent in a POST request contains the tag <message>Hello</message>.
Which Postman test assertion is correct?
Apm.expect(pm.request.body.text).to.have.string('<message>Hello</message>');
Bpm.expect(pm.response.text()).to.include('<message>Hello</message>');
Cpm.expect(pm.request.body.raw).to.equal('<message>Hello</message>');
Dpm.expect(pm.request.body.raw).to.include('<message>Hello</message>');
Attempts:
2 left
💡 Hint
pm.request.body.raw holds the raw request body as a string.
🔧 Debug
advanced
2:00remaining
Why does this Postman test fail with 'TypeError: Cannot read property "raw" of undefined'?
You wrote this test script:
const xml = pm.request.body.raw;
pm.test('Check XML', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});

But when you run it, you get:
TypeError: Cannot read property "raw" of undefined

What is the most likely cause?
Postman
const xml = pm.request.body.raw;
pm.test('Check XML', () => {
  pm.expect(xml).to.include('<to>Alice</to>');
});
Apm.request.body.raw is only available in pre-request scripts, not test scripts.
BThe request body is not set or is empty, so pm.request.body is undefined.
CYou must parse the XML before accessing pm.request.body.raw.
DPostman does not support raw XML bodies in requests.
Attempts:
2 left
💡 Hint
Check if the request body is configured in the request.
🧠 Conceptual
advanced
2:00remaining
What is the best way to validate the structure of a raw XML body in Postman tests?
You want to verify that the raw XML body sent in a POST request has a specific structure, for example, it contains a <note> root with <to> and <from> child tags.
Which approach is best in Postman test scripts?
AParse the raw XML string using a DOM parser library and check the presence of tags programmatically.
BUse pm.expect(pm.request.body.raw).to.include() with multiple string checks for each tag.
CConvert the XML to JSON using an external tool before sending the request and test JSON instead.
DUse regex matching on pm.request.body.raw to find the required tags.
Attempts:
2 left
💡 Hint
Postman test scripts can use JavaScript libraries to parse XML.
framework
expert
3:00remaining
How to automate testing of raw XML request bodies in a CI pipeline using Postman/Newman?
You have Postman collections with requests sending raw XML bodies. You want to run automated tests in a CI pipeline using Newman.
Which practice ensures reliable validation of raw XML bodies in this setup?
AInclude test scripts that parse pm.request.body.raw XML and assert structure/content using JavaScript XML parsers, then run Newman in CI.
BOnly check HTTP status codes in Newman tests, ignoring raw XML body validation to avoid complexity.
CConvert XML bodies to JSON before sending requests, so Newman can validate JSON easily.
DUse Newman environment variables to store XML strings and compare them as plain text in tests.
Attempts:
2 left
💡 Hint
Automated tests should validate XML content programmatically for reliability.