Forum Discussion
Hi richie
Most of time response of POST / PUT / DELETE is empty or just return a [] / {}. But the response status should be 200 if success. So firstly you need to determine if response is good. and then like what you said. Sending a GET request to check if update takes effect or not.
For example, if you delete a record, you may know its ID or name, then you needs to check if it really deleted in GET.
Adding "Valid HTTP Status Code" in assertion alongwith code=200, 202.
If have response, then simply check it thru script assertion if need
def response = messageExchange.response?.contentAsString if(response != null){ // example assert response.size() > 0, "No any content returned in Response" }
Regards,
/Aaron
- richie7 years agoCommunity Hero
Hi aaronpliu
thanks for the help - but I must be missing something important but obvious here - cos it didn't work as I expected.
I added the script assertion you provided on the GET request that I'm using to prove the record was deleted correctly. (just as an aside - I'm getting valid responses back from the application server so I'm not worried about checking for http status codes).
The script assertion you provided is below
def response = messageExchange.response?.contentAsString if(response != null){ // example assert response.size() > 0, "No any content returned in Response" }
When I forced the GET's response to include a body (e.g.by using the 'Accept' header with value of application/xml on the request) - I get an empty <results /> element in the outline tab and the script assertion 'passed'.When I forced the response to be completely empty (e.g.by using the 'Accept' header with value of application/json on the request) - I get nothing in the response payload (outline tab is empty) and the script assertion 'passed'. Admittedly if I look at the raw I do get [] - and I'm unsure if this is just SoapUI representing a blank response body or not.
You'll have to forgive me, my groovy is rubbish - but reading the above it appears that if there is a payload in response, then assert the response size is >0, (which I get) and return a message saying there isn't any content.??? I appreciate it appears you specified the assertion as possible example.
I played around with operands - or tried to - to assert when there is no payload in response, so the script is as follows:
def response = messageExchange.response?.contentAsString if(response == null){ // example assert response.size() == 0, "No content returned in Response" }
but again - whether there was a <results /> tag in the payload (forcing response to me XML) or whether the was nothing in the response (forcing response to be json) the script always passes!Am I missing something? essentially the script passes whether the response includes a payload AND when it doesn't!
I am very grateful for your help though!richie
Related Content
- 3 years ago
- 8 years ago
Recent Discussions
- 22 days ago