1

I'm running Karate tests from Java runner with Gradle. For monitoring purpose, I want to get the endpoint which is failing

For example, with this feature file:

Feature: health check

Scenario: Test endpoint which would almost always be successful
  Given url "https://google.com"
  Given path "/"
  When method get
  Then status 200

  Given path "/search"
  When method get
  Then status 500         # the test will fail here

  Given url "https://bing.com"
  When method get
  Then status 200

I want to get google.com/search; just google.com is fine, too.

I'm thinking of doing a linear search in the karate scenario results:

Results results = Runner.path(// ...)

// get the failing step
int failingStep = results.getScenarioResults().get(x).failedStep.step.index

// get the failing URL by looking at the 'results.getScenarioResults().get(x).stepResults',
// from the first step until the 'failingStep'

Is there a more proper way to do this?

Thank you

1 Answers1

1

No, Karate is not really designed for this. So I don't have any better suggestions other than looping over the results like you are doing.

That said, I wanted to remind you that loops are possible. And the loop will continue even if one fails. Also refer: https://stackoverflow.com/a/54108755/143475

Feature:

Scenario Outline:
* url urlBase
* method get
* status 200

Examples:
| urlBase                   | 
| https://google.com        |
| https://google.com/search |
| https://bing.com          |

Maybe you can figure out some better ways.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248