1
votes

I have written a Postman test script which is returning an xml in repsonse. But the test script is not running.

TestScript:

var jsonObject = xml2Json(responseBody);
console.log(jsonObject);
tests["TestCase"] = jsonObject.CreatePOReq.CreatePOReq.ProjectNumber === "3466703";

Response xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CreatePOReq ReturnStatus="Send to Vendor" GoetPONumber="806236" ProjectNumber="3466703">
    <line/>
    <header/>
</CreatePOReq>

Error : There was an error in evaluating the test script: TypeError: Cannot read property 'ProjectNumber' of undefined

Console Log: enter image description here

2

2 Answers

1
votes

please use the below code it will work definitely.

Use the '$' symbol instead of second 'CreatePOReq' value

 var jsonObject = xml2Json(responseBody);
 console.log(jsonObject);
 console.log(jsonObject.CreatePOReq.$.ProjectNumber);
 tests["TestCase"] = jsonObject.CreatePOReq.$.ProjectNumber === 
      "3466703";
0
votes

Is it OK to repeat CreatePOReq in the third line of your TestScript?

tests["TestCase"] = jsonObject.CreatePOReq.CreatePOReq.ProjectNumber === "3466703";