0

Problem in this Loop //Test to Check W2B001 is received same from API as well//Test that the response is an Int or date

I have an Array like this

"dates": [{
      "id": 1,
      "date": "2019-06-30T00:00:00"
    },
    {
      "id": 2,
      "date": "2019-04-30T00:00:00"
    },
    {
      "id": 3,
      "date": "2019-08-31T00:00:00"
    },
    {
      "id": 4,
      "date": "2019-10-31T00:00:00"
    },
    {
      "id": 5,
      "date": "2019-02-28T00:00:00"
    },
    {
      "id": 6,
      "date": "2018-12-31T00:00:00"
    }
  ]
};


pm.test("Verify that the Address Type and Datatype are matching the Soap UI response ", function () {
    for (var i = 0; i < jsonData.dates.length; i++)
        {
            var datedata = jsonData.dates[i].date;
            if (datedata === "2019-06-30T00:00:00") {
                pm.variables.set("test_status", "passed");
                console.log(datedata);
            }else
            {
                pm.variables.set("test_status", "failed");
            }
    }
    console.log(pm.variables.get("test_status"));
    console.log(datedata);
    console.log(jsonData.creditCommitments.length);
});

I want to validate that the date is matching, but the problem I am facing is that the postman received array element is not always received as sorted. So It passes once and not passing the second time. Any Idea how to fix it ?

  • Not sure what that `test` is doing for you, it will always pass as it doesn't have any `pm.expect()` statement to validate the values against. The code inside that test object can be extracted and run on it's own. – Danny Dainton Jan 09 '20 at 09:13
  • 1
    Few things are not cleared to me. 1) Why do you use a test? as per the code written, there isn't need of it. 2) Do you want to compare each date with a static date i.e. `2019-06-30T00:00:00`? 3) *I want to validate that the date is matching* do you want to compare that both strings are equal or not? – Divyang Desai Jan 09 '20 at 09:13

0 Answers0