Message Content Assertion: Assertion is looking for null fields even though it worked previously
When I run my call I get the following JSON object:
{
"data": {
"id": 159,
"zoneName": "NameofZone",
"createdAt": "2019-09-11 19:25:31",
"updatedAt": "2019-09-11 19:25:31",
"groupsId": null
},
"status": "success",
"code": "200",
"message": "Operation success",
"version": "2"
}
I setup a Content Assertion on the response to validate that the fields exist:
I can run this call any number of times back to back and the message content assertion will always pass.
However, when I run the entire Test Suite and the same step is run the message content assertion will always fail. It will give an error as if it were trying to find null nodes in the response (shown below)
Any idea or insight into why this is happening? Is there any way to prevent this? Currently I am removing the contract assertion from the test case but that kind of defeats the purpose of the test.
The dev team got back to me today. The issue is with the URL. Since this is a call that requires a template parameter for the ID, when the assert is created it is created with the ID in the URL. When I run the test from the test suite level, a new group is created, thus a new group ID is created which does not match the ID listed in the URL for the content assert. Below is the direct reply from the team:
Message Content Assertion is based on xml object and it converts all json nodes into xml nodes and declares namespace ns1=endpoint.
When the assertion was created the endpoint was http://{APIURL}/api/zones/165.
If you open XML tab in the response you will see something like <Response xmlns="http://{APIURL}/api/zones/179">. And the namespase for the got response and in the assertion are different, that's why the assertion fails.
The node cannot be found at all
They suggested to substitute the assertion for the JSONPath Existence Match which is more preferable for json responses and independent of endpoint.