使用从一个场景到另一个场景的响应数据
Using response data from one scenario to another
对于空手道,我希望模拟一个端到端的测试结构,我在其中执行以下操作:
- 对特定数据发出 GET 请求
- 将值存储为
def
变量
- 将该信息用于单独的场景
这是我目前拥有的:
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.....
我尝试阅读文档以重用信息,但这似乎是为了进行更深入的测试。
想法?
强烈建议将这样的流程建模为一个场景。请参考文档: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 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
或钩子就是您要找的东西:https://github.com/intuit/karate#hooks
对于空手道,我希望模拟一个端到端的测试结构,我在其中执行以下操作:
- 对特定数据发出 GET 请求
- 将值存储为
def
变量 - 将该信息用于单独的场景
这是我目前拥有的:
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.....
我尝试阅读文档以重用信息,但这似乎是为了进行更深入的测试。
想法?
强烈建议将这样的流程建模为一个场景。请参考文档: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 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
或钩子就是您要找的东西:https://github.com/intuit/karate#hooks