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.
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);
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.