1

I want to recover an object id (processId) that I pass in a simple Post request in a feature A

Given url <url>
    And path 'processes'
    And header Authorization = 'Bearer ' + <token>
    And request process
    When method post
    Then status 201

    * def processId = response.id

I test this request with 3 different environments in a Scenario outline (varriable <url>). So I have to recover the 3 id to use them in a feature B

My question is: how can I retrieve these IDs for use in feature B

Thanks

Olivier
  • 343
  • 2
  • 16

1 Answers1

1

There is no way you can re-use data from one Scenario in another, and a Feature is certainly out of the question. Please take some time to read this: https://stackoverflow.com/a/46080568/143475

That said, if all you need to do is call a Scenario in a loop, just do that. Here is a simple example you can try:

Feature:

Scenario:
* table data
| value |
| 'one' |
| 'two' |
* def result = call read('called.feature') data
* def traceIds = $result[*].traceId
* print traceIds

And called.feature is simply:

@ignore
Feature:

Scenario:
* url 'https://httpbin.org/post'
* request { key: '#(value)' }
* method post
* def traceId = response.headers['X-Amzn-Trace-Id']

Please read the docs to understand how you can "collect" data from the "called" feature, traceId in this case: https://github.com/karatelabs/karate#data-driven-features

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248