Verify Element Property, not Property Value

I am familiar with the Verify Element Property Value web service command but I am curious if there is a way to strictly check for the response property only, without needing to also provide a value.

Yeah, I’ve read your post a cpl times. Problem is, I don’t do webservice calls this way. So to help me help you, post some code, perhaps your data too (you can edit it down to just the bare essentials) then maybe I can take a shot.

Btw, you shouldn’t assume lack of an answer means nobody is reading… sometimes people just don’t know what to say to advise.

1 Like

I believe this is what the verifyElementsCount() method is for:

https://docs.katalon.com/katalon-studio/docs/ws-verify-elements-count.html

In other words:

WS.verifyElementsCount(response, 'json.path.to.property', 1);

1 Like

Yes this is what the verify elements count achieves but sadly it only returns the element count, not the name of the properties or values. Say I have a Json object returned such as [{ firstName: Jon, lastName: Smith }, { firstName: Tim, lastName: Timson }]. Verify Element Count will only output a boolean based on the provided input matching the number of elements returned or not. So if:

WS.verifyElementsCount(response, '[0]', 2)

True will be returned since the first object in the array of returned elements holds two property/value pair. Unfortunately this is all this does, at least to my knowledge and can’t be used to figure out [0].property = firstName.

To iterate further utilizing the example provided above:

I also tried doing something like WS.verifyElementsCount(response, ‘[0].firstName’, 1) but was returned an error stating Unable to verify element count (Root cause: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.size() is applicable for argument types: () values: [].

Correct me if I’m wrong but I believe this says that it fails because it’s not looking directly at an array.

Right, then in this case, you make the JSONPath point to the exact object you are trying to validate the existence of:

WS.verifyElementsCount(response, '$..array_object[?(@.firstName=='Jon' && @.lastName=='Smith')]', 1);

I’m nowhere near a JSONPath expert, but it would look something like that.

If you are able to post the entire JSON response, I can help you find a good JSONPath. Not sure if the data contains sensitive info…

just found this thread related to what i wanted to verify, instead of using assertion.
use katalon WS.verifyElementsCount

my test case already define ‘ref’ to get the API response, i got the response as below:
how to find child under ‘itemReports’?
e.g. first ‘itemReports’ has one, second ‘itemReports’ has 1, third ‘itemReports’ has four

{
“created”: “2019-11-21T06:39:58.4971147Z”,
“OrderId”: “6021112019023958”,
“items”: [
{
“id”: “6ba33d07-ea1b-4d0d-8013-0f1b21c0e399”,
“itemId”: “Augmentn”,
“itemReports”: [
{
“activity”: “COMPLETED”,
“expirationDate”: “2029-10-16T00:00:00”,
“itemId”: “6ba33d07-ea1b-4d0d-8013-0f1b21c0e399”,
“itemIdentifier”: “B6699945634111c”
}
],
“quantity”: 100
},
{
“id”: “d97ca167-4fd4-452b-afd4-12fa6283c62a”,
“itemId”: “Adenosine”,
“itemReports”: [
{
“activity”: “COMPLETED”,
“expirationDate”: “2029-05-01T00:00:00”,
“itemId”: “d97ca167-4fd4-452b-afd4-12fa6283c62a”,
“itemIdentifier”: “B6699945634222d”
}
],
“quantity”: 300
},
{
“id”: “f2c5623e-55ed-42eb-8a33-9f85a763cdbc”,
“itemId”: “Clopidogrl”,
“itemReports”: [
{
“activity”: “STOCKOUT”,
“expirationDate”: “2029-10-16T00:00:00”,
“itemId”: “f2c5623e-55ed-42eb-8a33-9f85a763cdbc”,
“itemIdentifier”: “B6699945634222c”
},
{
“activity”: “COMPLETED”,
“expirationDate”: “2029-05-01T00:00:00”,
“itemId”: “f2c5623e-55ed-42eb-8a33-9f85a763cdbc”,
“itemIdentifier”: “B6699945634222c”
},
{
“activity”: “COMPLETED”,
“expirationDate”: “2029-05-01T00:00:00”,
“itemId”: “f2c5623e-55ed-42eb-8a33-9f85a763cdbc”,
“itemIdentifier”: “B6699945634888d”
},
{
“activity”: “COMPLETED”,
“expirationDate”: “2029-05-01T00:00:00”,
“itemId”: “f2c5623e-55ed-42eb-8a33-9f85a763cdbc”,
“itemIdentifier”: “B6699945634999d”
}
],
“quantity”: 200
}
],
“lastModified”: “2019-11-21T06:43:28.8050958Z”
}

to check if a given key exist in the response, a better aproach will be to use Json schema validation (search the forum and you may find relevant topics on this matter)

i did not see how json schema validate my case about the size of child line item.
did not find useful syntax at the owner github too.
not going to invest this method further. will use assertion instead since katalon verify count isn’t the one for this case too.