1

I'm using Karate for my API tests and I'm trying to output the response from the last request. I have a test that looks like this:

Feature: Retry HTTP GET request until response status 207

Given url 'http://example.com'
And path '/'
And retry until responseStatus == 207
When method get

When this test fails, the output I get is quite minimal, like this:

When method get
too many retry attempts: 3

However, this doesn't give me much information about why the request failed. I'd like to see the output (specifically the body, header and the status code) of the last response to get a better understanding of what's happening.

I've looked in Karate's documentation but I can't find a straightforward way using the retry until syntax. I came across a potential solution in the 'polling.feature' example, but it seems overly complex for what I'm aiming to achieve. Does anyone have suggestions on how to print the response in a simpler way?

Absurd-Mind
  • 7,884
  • 5
  • 35
  • 47

1 Answers1

1

Refer the part in this answer on re-using a JS function: https://stackoverflow.com/a/55823180/143475

That may give you some ideas. For example in that function you can do karate.get('response') etc. You can call karate.log() also.

working example:

* def isValid = function(response, status) { karate.log(response); return status == 207; }
And retry until isValid(response, status)
Absurd-Mind
  • 7,884
  • 5
  • 35
  • 47
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248