有没有办法像Java方法链接那样将空手道中的场景链接起来 [英] Is there a way we can chain the scenarios in karate like java method chaining
问题描述
过去6个月来我一直在使用空手道,它的功能给我留下了深刻的印象. 我知道空手道是用于单独测试API的,但我们也正尝试将其用于端到端测试,该测试涉及逐步调用多个方案. 我们的功能文件如下所示 1.呼叫功能1:场景1 2.致电Feature2:Scenario2 ..... 注意:我们正在将场景重新用于API测试和E2E测试,有时我很难记住所有功能文件. 我们是否可以像Java那样链接场景调用,我怀疑功能文件是否可以做到这一点.我们需要您的宝贵建议.请让我们知道您是否认为我们的方法不正确
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
推荐答案
首先,我想引用一下文档: https://github.com/intuit/karate#script-structure
First, I'd like to quote the documentation: https://github.com/intuit/karate#script-structure
在每个
Scenario
之前将重新设置在后台使用def设置的变量.如果您正在寻找一种方法,每个Feature
仅做一次,请查看callonce
.另一方面,如果您希望Background
中的变量被一个Scenario
修改,以便以后的用户可以看到更新的值-那不是您应该怎么看的,您应该结合使用'流入一个Scenario
.请记住,您应该能够注释掉Scenario
或通过标记跳过某些内容,而不会影响其他任何内容.请注意,并行运行器将并行运行Scenario
-s,这意味着它们可以以任何顺序运行.
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.
因此,默认情况下,我实际上建议团队在其中包含多个API调用的Scenario
-s.这没什么不对,我真的不明白为什么有些人认为每个GET
或POST
等都应该有一个Scenario
.我认为可以明确说明,但显然不是.
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.
如果Feature
中有多个Scenario-s
,只需运行该功能,所有Scenario-s
将被执行或链接".那是什么问题呢?
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 ?
我认为您需要更改一些假设.空手道是专为集成测试而设计的.如果确实需要使用一组单独的测试来一次测试一个API,请创建单独的功能文件.空手道的全部要点是,只需要很少的代码-完全可以进行代码复制.
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.
让我指出您 Google撰写的这篇文章.为了实现测试自动化,您不应该尝试在各处重复使用.弊大于利.
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.
有关在空手道中尝试过度使用"时会发生什么的一个很好的例子,请参见: https: //stackoverflow.com/a/54126724/143475
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
这篇关于有没有办法像Java方法链接那样将空手道中的场景链接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!