How to get response HTTP status from Karate Call? Getting response status as 204 but karate.log(result.response) is blank

Viewed 3226

I'm calling a webservice through Karate API. When the service is executed, I am getting HTTP status 204 which is expected. However, when I log the response, I get blank.

Below is my webservice call, response and log output

    result = karate.call('ExecuteWebService.feature', [urlToExecute]);
    karate.log("Response is " + result.response); #Expecting that code displays HTTP status here

I know am getting proper response for call because my logs show below content

    HH.mm.ss.mil [main] DEBUG com.intuit.karate - 
    1 < 204
    1 < Date: Fri, Rest of date portion
    1 < X-Application-Context: App Context Data

However karate.log doesn't display the status code. I need status code so I can assert the status against my expected values and thus pass/fail the test

    HH.mm.ss.mil [main] DEBUG com.intuit.karate - response time in milliseconds: 431
    HH.mm.ss.mil [main] INFO com.intuit.karate - [print] 
    HH.mm.ss.mil [main] INFO com.intuit.karate - Response is  

Can you advice on how to extract HTTP status from karate.call result so I can assert the response?

2 Answers

This should work,

* def status = result.responseStatus

similary you can also access response, responseTime, responseHeaders, responseCookies

204 response code means:

The server has successfully fulfilled the request and that there is no additional content to send in the response payload body

So, it is normal, that you don't have anything in response body.
In your case, I would verify only that status code is correct (according application specifications).

Related