-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make karate.scenario available to use in mock feature files #2618
Comments
@maggiesid will tag this as help wanted as no one has asked for this so far. I recommend that you or someone in your team looks at the code and contributes a PR, it should be easy BTW I think the header approach you seem to be using now as per the stack-overflow post is a reasonably good one |
Hi @ptrthomas thank you very much for your quick reply! Do you have any hint about where to contribute in Karate codebase to make karate.scenario available in mock feature files? Thank you in advance for your cooperation |
@maggiesid I'll try. the mock handling happens here: https://github.com/karatelabs/karate/blob/v1.5.0/karate-core/src/main/java/com/intuit/karate/core/MockHandler.java#L157 initEngine() sets up a dummy scenario, so maybe some way to update that to reflect the final resolved scenario ... |
Hi @ptrthomas I have been investigating this and I have one doubt: Problem is that I would need to print, inside a mock feature file scenario (M1.feature), the name of the test scenario that I am executing in T1.feature `// T1.feature // M1.feature So I would need to print "scenario 123" while I am executing scenario pathMatches('/downstream/path/api/v0') of M1.feature file Given that MockServer objects are started while setting up the testsuite running, independently from the scenarios I see that the MockServer object runs independently by the test scenario I am executing Thank you again for your cooperation |
yes mocks are designed to be independent. if you really want some connection between some test and the mock, either you continue to use something in the HTTP request (like headers which you are already doing) or you have no option but to build this integration yourself. this sample should give you enough pointers: https://x.com/getkarate/status/1417023536082812935 |
As proposed in this StackOverflow thread started by a teammate of mine
https://stackoverflow.com/questions/78927512/select-mock-file-to-use-based-on-the-running-karate-scenario
problem: I have some Karate Scenarios to test my application and I'm using a Karate MockServer as mocked downstream service.
To simulate edge case scenarios (e.g. empty results from downstream), I want to select a specific mock file based on the running Karate Scenario. Is there a way to know which is the Scenario that triggered the downstream mock call?
We have been suggested by Peter Thomas to use karate.scenario but currently it does not work for mocks
We would need to extend karate to allow the usage of it in mock files as well
The text was updated successfully, but these errors were encountered: