Reputation: 1
I have response in JSON, there are many nested properties inside. How to validate some text or numeric values between csv/json test data file and values in the json response. For example if certain IDs or titles in CSV/JSON complies with JSON body response. I can save JSON response as a global variable, but what to do next??
How to compare CSV data file with associated properties in JSON response?
Let's say I want to validate title value from CSV against following response:
[
{
"title": "Rules of Procedure",
"taxonomyCategoryId": 48984123,
"taxonomyCategoryName": "Legal documents"
}
]
in post response scripts I have this:
pm.test("Response value matches expected value", function () {
// this is the element you get from the response
var jsonData = pm.response.json().title;
// this is the element coming from the data file
pm.expect(jsonData.title).to.eql(pm.iterationData.get("title"));
});
CSV test data structured like this:
"title"
"Rules of Procedure"
When running collection with that request and test data csv (same when test data is in JSON format), I'm having this error:
AssertionError: expected undefined to deeply equal 'Rules of Procedure'
I believe that there is something wrong with that line of post-script syntax:
pm.expect(jsonData.title).to.eql(pm.iterationData.get("title"));
Upvotes: 0
Views: 170