Hello guys! I’m beginner on this website, so i hope you will help me
I got trouble while i made my tests. I have a loop which need to assert values from my CSV with my array in JSON. But if test is passed, i need to move on next iteration, while my loop starts checking all the values in array.
This is example of code:
var jsonData = pm.response.json();
const schemaOfUndifined = {
"type": "object",
"properties": {
"code": {
"type": "string"
}
},
"required": [
"code"
]
}
try {
if (jsonData != schemaOfUndifined && pm.iterationData.get("attribute_id") != "" && pm.iterationData.get("offer_id_4") == jsonData.id) {
try {
for (let i = 0; i < jsonData.mainArray[0].arrayWithMyValuesToCheck.length; i++) {
if (pm.iterationData.get("attribute_id") == jsonData.mainArray[0].arrayWithMyValuesToCheck[i].valueId) {
pm.test("Check that attributeId of - " + jsonData.id + " equals to attribute_id value in csv as - " + pm.iterationData.get("attribute_id"), function () {
pm.expect(pm.iterationData.get("attribute_id")).to.eql(jsonData.mainArray[0].arrayWithMyValuesToCheck[i].valueId);
});
}
}
} catch (t) {
console.log(t)
}
}
} catch (e) {
console.log(e)
}
Response body:
{
"id": "AO1012",
"mainArray": [
{
"id": "01",
"arrayWithMyValuesToCheck": [
{
"valueId": "VALUE03",
},
{
"valueId": "VALUE07",
}
]
}
]
}
My csv:
AO1012,VALUE03,
AO1012,VALUE07@#, - and this need to send me error message, but it just doesn’t checking anything
And if test is True, i need to move on next iteration in pm.iterationData.get(“attribute_id”), and if it’s False i need to send error message and move on next iteraion