I created a mock server using Karate and want to count the traffic accessing the mock server. According to the Karate test writing method, I output logs in "background" to count the inbound time of all requests.
The results are not smooth, it was only executed once on mock server startup, and not executed when the request is inbound.
Feature:
Background:
* url "http://localhost:8081"
* configure afterScenario = logExternalApi
* def now = function() { return new Date().toString();}
* karate.log(now())
In Karate mock server, is there a way to control "Before Scenario"? Alternatively, is there another way to customize the action when requesting inbound?
This is an open feature request: https://github.com/karatelabs/karate/issues/2239
For now you may be able to work-around by writing a re-usable JS function and calling it in multiple places. Please do contribute open-source code via a PR of possible.