4

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?

JMD
  • 337
  • 4
  • 16

2 Answers2

5

This should work,

* def status = result.responseStatus

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

Babu Sekaran
  • 4,129
  • 1
  • 9
  • 20
  • one more thing you can access all the variables that you defined in you called feature as well. – Babu Sekaran Dec 28 '18 at 17:48
  • print your 'result' variable to see all the data returned from your karate.call – Babu Sekaran Dec 28 '18 at 17:57
  • 1
    Yes, I tried that. It printed something like com.intuit.karate.ScriptObjectMap@423c5404. So wasn't sure how to get data out of the ObjectMap. What you answered was something I was looking for – JMD Dec 28 '18 at 18:28
0

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

Ukrainis
  • 534
  • 2
  • 16
  • How do I get the status code from result? Currently karate.log() display blank for status code and not 204 – JMD Dec 28 '18 at 17:33