使用从一种情况到另一种情况的响应数据

问题描述:

我想通过空手道来模拟一个端到端的测试结构,在其中执行以下操作:

With Karate, I'm looking to simulate an end-to-end test structure where I do the following:

  1. 对特定数据进行GET请求
  2. 将值存储为def变量
  3. 将该信息用于单独的场景
  1. Make a GET request to specific data
  2. Store a value as a def variable
  3. Use that information for a separate scenario

这是我到目前为止所拥有的:

This is what I have so far:

Scenario: Search for asset
    Given url "https://foo.bar.buzz"
    When method get
    Then status 200
    * def responseItem = $.items[0].id // variable initialized from the response
Scenario: Modify asset found
    Given url "https://foo.bar.buzz/" + responseItem
    // making request payload
    When method put.....

我尝试阅读文档以重用信息,但这似乎是为了进行更深入的测试.

I tried reading the documentation for reusing information, but that seemed to be for more in-depth testing.

有想法吗?

强烈建议将这种流程建模为一种情况.请参阅文档: https://github.com/intuit/karate#script-structure

It is highly recommended to model flows like this as one scenario. Please refer to the documentation: https://github.com/intuit/karate#script-structure

使用def在后台设置的变量将在每次 设想.如果您正在寻找一种方法,每次只能做一次 功能,看一下callonce.另一方面,如果您是 期望后台中的变量被一种情况修改 这样以后的人就可以看到更新后的值-这不是您的方式 应该考虑它们,并且应该将流"合并为一个 设想.请记住,您应该可以注释掉 场景或通过标记跳过一些而不影响其他标记.注意 并行运行程序将并行运行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 per Feature, take a look at callonce. On the other hand, if you are expecting a variable in the Background to be modified by one Scenario 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 one scenario. Keep in mind that you should be able to comment-out a Scenario or skip some via tags without impacting any others. Note that the parallel runner will run Scenario-s in parallel, which means they can run in any order.

也就是说,您可能正在寻找Background或hooks: https://github.com/intuit/karate#hooks

That said, maybe the Background or hooks is what you are looking for: https://github.com/intuit/karate#hooks