Verify WebService Response field not empty

Thoughts on the best way to verify a field in a WebService response is NOT empty? If so, I want to stop test execution and log a warning (which is my other question - I don’t see an option for KeywordUtil.markwarning and stop. In this particular case, a warning seems to be more appropriate since the issue is on a 3rd party and not us.

Thanks!
Morgan

Oh Morgan, come on, you know we need to see code. But hang on, let me turn on my supersense powers.

if(fieldOfInterest != null && fieldOfInterest != "") {
  doSomethingFabulous()
}

Warnings are not “stop” things. The only thing I can think of is to markWarning, then markFailed and/or throw an exception.

Sorry, I had very little worth sharing, mucked with a few things but couldn’t get it working…

WS.verifyElementPropertyValue(response, "banners", "") == true {
	KeywordUtil.markWarning("No ads returned for retailer")
	}

But obviously that’s not right since it does the verify and bombs with “Expected element property value ‘’ is not equal with actual property value” . Will play around a bit with what you suggest. Thanks!

1 Like

@Morgan I just looked at that again - was that meant to be an IF construct? I don’t think a mere boolean expression can prefix a closure.

GAH, you are right. Like I said, I’d played around a bit. I’d not included the If when I shared that. :woman_facepalming:

LOL - fair enough.

I’m intrigued to know what this produces:

println WS.verifyElementPropertyValue(response, "banners", "").toString()

Might not need toString - just giving it no excuses to fail on us.

I am so stinking close… in this case, I should report a failure yet, we’re not.

ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()

def slurper = new groovy.json.JsonSlurper()
def result = slurper.parseText(response.getResponseBodyContent())
def ads = result.ads

if(ads == " ") {
	KeywordUtil.markWarning("No ads returned from vendor")
	throw new AssertionError('ERROR: No ads available')
}

I’ve tried ads== " " and without a space and null but nadda. :thinking:

if(ads == [])
2 Likes

You could also instead check for ads.size() == 0

Thank YOU for putting me out of my misery. IT WORKS! And great suggestion, I’ll add that. :partying_face:

1 Like

one or the other, not both. I’d prefer the latter.

looks for my eyes you are trying to handle validations from request object himself.
altough may be a good reason for that (kind of how postman do it), with katalon a better approach will be to handle validations on the test case script and use the request just for it’s purpose. send / receive
in the context of testcase some mark.failed make sense. in request object scope, not.

you can watch the test case in katalon as something above the request, which you can further manipulate.
don’t set the logic for validation on the request object himself unless for quick development /trial and error, otherwise you are just cluttering them witn not needed actions.

with your current approach, to enforce the testcase fail, you have to use plain assert in the request verification snippet.

Looks like they have method to verify values equal but not unequal. Till then I would just do this -

assert WS.getElementPropertyValue(response, 'ads') != ' '