Forum Discussion
Hey zht2970781
the wildcard functionality appears to work if you are asserting a specific json attribute value. It looks like ReadyAPI is treating the asterisk '*' like a literal instead of a control character when asserting against >1 attribute in the JSONPath Expression assertion type.
I think this is because you are asserting against the content of multiple attributes (you're asserting against the whole payload) rather than a specific field.
I tried asserting against the whole payload (like you've done) whilst trying to escape the wildcard - but I cant find a solution that work - tried multiple options for escaping the asterisk - but nothing was successful. I'm unsure if you can wildcard when asserting on multiple attributes at the same time......???
Perhaps one of the other forum users knows a way of doing this....especially the SmartBear representatives, but a possible work around is that you use the SmartAssertion against all the attributes in the payload EXCEPT the one you want to wildcard.
Then add a separate JSONPath Expression for the wildcard field only
This would get around the above restriction you've found.....well....if in fact wildcards dont work when asserting on >1 json attribute....
Cheers,
Rich
Thank you Richie for the help.
Unfortunately, I can't use SmartAssert as the assertion should only happen on the nested object that meets my condition. So it is dynamic and the sequence is not guaranteed. So my case is the endpoint could return an array of X objects, during the X there should be 1 object that has a "boardwalkDeposit" property, which I will need to assert that it has a id, sequenceNumber and amount etc. Since "id" is generated, so I have to use wildcard on it to check it is not null. Ideally, I should check id is some sort of number but I don't think ReadyApi can do that in JSONPath expected results.
I guess what I can do is creating multiple JSONpath check steps for each of the properties under "boardwalkDeposit" object. Personally, I do believe this issue should be concerned as BUG or limitation of ReadyAPI that should be highlighted in their documentation.
- zht29707813 years agoNew Contributor
OH... another question or limitation. I just tested for JSONPath Match Assertion, if I use "*" on a single property that does not even exist, the test still passes.... how can I assert a dynamic property is some sort of number or at least not null?
Picture attached, I want to make sure the matching nested object has a number property called id and it can not be null. Its value is auto-generated so it is dynamic.
- richie3 years agoCommunity Hero
Hey zht2970781
you can use regex (I'm on the wrong machine right now) so I cant give you the exact name of the assertion, but there's an assertion that supports regex which would allow you to assert an attribute value is of numeric type
you can also do a script assertion using regex as well
as to your scenario of verifying both is numeric and is not null you could do something like the following in a script assertion:
def response = context.expand( '${REST Request#Response}' )
def numericAttribute = parse(response).read('$.id.numericAttribute')
log.info numericAttribute
assert (numericAttribute != null) && (numericAttribute ==~ /[0-9{3}/)
so hopefully (if I've got it right - there might be a mistake in there - I was rushing and going off memory, but hopefully it'll give you a steer) - the above assertion will parse the numericAttribute from the response (with JSONPath $.id.numericAttribute) and assert the attribute is not null and the value is made up of only 3 numbers. think you can use a \d to represent numerics here too - but I'd have to google to be sure and Im a bit pressed for time today.
hope the above helps,
Cheers,
Rich
- sonya_m3 years agoSmartBear Alumni (Retired)
Related Content
- 10 years ago
- 7 years ago
Recent Discussions
- 18 days ago