I have been using Karate for the past 6 months, I am really impressed with the features it offers. I know karate is meant to test API(s) individually but we are also trying to use it for E2E tests that involves calling multiple scenarios step by step. Our feature file looks like below 1.Call Feature1:Scenario1 2.Call Feature2:Scenario2 ..... Note: We are re-using a scenarios for both API Testing and E2E testing.Sometimes I find it difficult to remember all feature files. Can we chain the scenario call like java, I doubt feature file will let us to do that. We need your valuable suggestion. pls let us know if you feel our approach is not correct
-
I need more Information. What do you mean by API and E2E testing? Both could be done by a CI Job or could be put into a separate E2E testing application that runs like any other normal application in the cloud. What do you mean by "Cannot remember all feature files"? Are you using karate in manual test cases and you have to call all scenarios manually? Would be great If you could describe a classical API Test (what you do aso.) and how this is different from an E2E test. – Peter Dec 20 '19 at 20:29
-
I have attached the picture that differentiates 2. – Muhil R Dec 20 '19 at 20:57
-
Ok, understood the way you create feature files that serve as a composition of other reusable scenarios. And I guess your are calling E2E feature files selectively in your test automation? And,.. the screenshot shows a cheat sheet? This isn't a screenshot from karate code, is it? – Peter Dec 20 '19 at 21:03
-
yes that is correct, I am sorry pls consider the image that explains the intent. I am planning to use karate for Integration/load/component and E2E. If I could chain the call (with intellij suggestion) I can achieve all these things.:) – Muhil R Dec 20 '19 at 22:26
1 Answers
First, I'd like to quote the documentation: https://github.com/intuit/karate#script-structure
Variables set using def in the Background will be re-set before every
Scenario
. If you are looking for a way to do something only once perFeature
, take a look atcallonce
. On the other hand, if you are expecting a variable in theBackground
to be modified by oneScenario
so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into oneScenario
. Keep in mind that you should be able to comment-out aScenario
or skip some via tags without impacting any others. Note that the parallel runner will runScenario
-s in parallel, which means they can run in any order.
So by default, I actually recommend teams to have Scenario
-s with multiple API calls within them. There is nothing wrong with that, and I really don't understand why some folks assume that you should have a Scenario
for every GET
or POST
etc. I thought the "hello world" example would have made that clear, but evidently not.
If you have multiple Scenario-s
in a Feature
just run the feature, and all Scenario-s
will be executed or "chained". So what's the problem ?
I think you need to change some of your assumptions. Karate is designed for integration testing. If you really need to have a separate set of tests that test one API at a time, please create separate feature files. The whole point of Karate is that there is so little code needed - that code-duplication is perfectly ok.
Let me point you to this article by Google. For test-automation, you should NOT be trying to re-use things all over the place. It does more harm than good.
For a great example of what happens when you try to apply "too much re-use" in Karate, see this: https://stackoverflow.com/a/54126724/143475

- 54,465
- 21
- 84
- 248