1

I am doing a test case where it will call API and that data will use next API call as part of One Scenario. I am passing testdata as part of example 4 records .Here I have under one scenario first Given API call output passing to second given API call.As part of comapare the results i need the first API call output data to compare with second API call results.

So is there any way to capture all four test records data first API call data in one variable (each time variable to update)

example : *def var = 'hello'

  • var = var +'world'

Please need help

Ramachari
  • 11
  • 3

1 Answers1

0

Please read the docs, copied below for convenience: 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.

So please don't expect a variable in one Scenario to be update-able by another Scenario.

But within a Scenario if you want to "collect" data, there are many ways. For example try appending to a list - refer: https://github.com/intuit/karate#json-transforms

* def init = []
# do some API call
* karate.appendTo(init, response)
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248