Karate test framework. Are there plans to include RuntimeHooks for MockServer?

43 views Asked by At

in our project we´re using Karate Mock Server to Mock external dependencies to our application under test.

We would like to track (and potentially do other validations) for each and every endpoint of the Mock Server that our application is interacting with.

We can see there is an afterScenario hook that can be configured but seems it has some restrictions compared to the RuntimeHooks that could be configured in the "normal" scenarios.

For example, we cannot get the details of each mock service scenario (representing and endpoint) by using the karate.scenario object within the afterScenario javascript method configured. Specifically, we were trying to get the tags at scenario level but with this approach we always get the tags at feature level instead.

Of course there is a way by including the call with the necessary parameters in each and every scenario of the Mock Server but this could end up in repeating the same code in many places. That´s why the hooks seems to be the best option.

So wonder if there is any way to have similar capabilities than Runner.path(x).hook() but for MockServer so that we could have all the hooks available. If that is not allowed, could you please let us know if there is any constraint in doing that ? Just for our knowledge.

We tried including this in the Background section of the Mock Server:

Background:
* configure afterScenario = function() { karate.log(karate.scenario) }

but showing always the same details for all the scenarios. eg:

{
  "sectionIndex": -1,
  "stepResults": [
  ],
  "line": 0,
  "description": null,
  "durationMillis": 0.0,
  "failed": false,
  "tags": [       <-- this shows the tags set at Feature level but not the ones at Scenario level
    "openapi=openapi/openapi-demo.yaml", 
    "mock"
  ],
  "executorName": null,
  "name": null,
  "startTime": 0,
  "refId": "[0:0]",
  "endTime": 0,
  "exampleIndex": -1
}
0

There are 0 answers