Using response data from one scenario to another

那年仲夏 提交于 2019-12-11 12:27:23

问题


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

  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.

Thoughts?


回答1:


It is highly recommended to model flows like this as one scenario. Please refer to 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 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.

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



来源:https://stackoverflow.com/questions/55927968/using-response-data-from-one-scenario-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!