Extracting data from response and validating it

I want to write a test in postman to validate data inside pli:GuidSequenceID that it is guid and is not null or 0. How can I access that data from side that tag and validate it that if it is the in GUID format or not. I am getting the response in xml format.

<?xml version="1.0"?>

<pli:GetJooyaltyOnlineStatusResponse
<pli:ResponseHeader overallResult=“success”>
pli:JooyaltyInterfaceVersion1.36.0</pli:JooyaltyInterfaceVersion>
nax:VendorNameSome Name</nax:VendorName>
nax:VendorModelVersionSomething1e</nax:VendorModelVersion>
pli:JoSequenceIDBUL 000001 10001 0000050</pli:JoSequenceID>
pli:GuidSequenceIDe2ab2f57-599b-477d-b9d3-3711241fb3d6</pli:GuidSequenceID>
pcs:Result

</pcs:Result>
</pli:ResponseHeader>
<pli:PromptForJooyaltyFlag value=“no” />
</pli:GetJooyaltyOnlineStatusResponse>


trying this approach for solution but not working as I am getting error saying
" TypeError: Cannot read property ‘pli:LoyaltySequenceID’ of undefined "
pm.test(“Converting xml to json”, function () {
var jsonData = xml2Json(responseBody);
console.log(‘JSON response’, jsonData);
let LoyaltyID = jsonData[‘pli:GetJooyaltyOnlineStatusResponse’][‘pli:ResponseHeader’][‘pli:JooyaltySequenceID’];
console.log('LoyaltyID is : ', LoyaltyID);
pm.expect(pm.jsonData[‘pli:JooyaltySequenceID’].to.equal(“0”));
});

@masounj

From the solution you posted I wasn’t sure if you were trying to get the pli:JoSequenceID or the pli:GuidSequenceID, so in my solution I just used both. When I run this locally in a mock with the example response you provided it all passes.

//Convert XML response to JSON
var jsonData = xml2Json(responseBody);
console.log("JSON response", jsonData);

//Get JoSequenceID value
var JoSequenceID = jsonData["pli:GetJooyaltyOnlineStatusResponse"]["pli:ResponseHeader"]["pli:JoSequenceID"];
console.log("JoSequenceID is", JoSequenceID);

//Test JoSequenceID is not null
pm.test("JoSequenceID is not null", function () {
pm.expect(JoSequenceID).not.eql(null);
});

//Test JoSequenceID is not 0
pm.test("JoSequenceID is not 0", function () {
pm.expect(JoSequenceID).not.eql(0);
});

//Get GuidSequenceID value
var GuidSequenceID = jsonData["pli:GetJooyaltyOnlineStatusResponse"]["pli:ResponseHeader"]["pli:GuidSequenceID"];
console.log("GuidSequenceID is", GuidSequenceID);
var regex = /^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$/;

//Test GuidSequenceID is not null
pm.test("GuidSequenceID is not null", function () {
pm.expect(GuidSequenceID).not.eql(null);
});

//Test GuidSequenceID is not 0
pm.test("GuidSequenceID is not 0", function () {
pm.expect(GuidSequenceID).not.eql(0);
});

//Test GuidSequenceID is a GUID
pm.test("GuidSequenceID is a GUID", function () {
pm.expect(regex.test(GuidSequenceID));
}); 

Mick

3 Likes