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