title: Karate: AfterScenario with parameter and in loop
body: <p>I couldn't find any solution for my problem so I hope someone will be able to help me.</p>
  <p>Basically I'm trying to test micro service architecture which depends on the main system.</p>
  <p>I created test data located in <code>helper-create-test-data.feature</code></p>
  <pre><code>Feature: Functionality of creating test data. The main goal of this helper is to create a certain test data
    and use it for testing a proper features and microservices.
  
    Background:
      * configure report = { showLog: true, showAllSteps: false }
  
    @create-multiple-adverts
    Scenario Outline: Advert with type - &lt;type&gt; - successfully paid
      * def advert_request = read('classpath:utilities/creation-request.json')
      * def authentication = callonce read('classpath:utilities/helper-authenticate-user.feature')
      * def access_token = authentication.access_token
      * def timestamp = result.timestamp
      * set advert_request.params.type = '&lt;type&gt;'
      * set advert_request.category_id = &lt;category_id&gt;
  
  
      Given url baseUrl
      And header Authorization = 'Bearer ' + access_token
      And path 'acc/ad'
      And request advert_request
      When method post
      Then status 201
      And print &quot;Advert successfully created with &quot; + __row
      And def advert_id = $.id
      Given path 'acc/ad/' + advert_id + '/activate'
      And header Authorization = 'Bearer ' + access_token
      And request ''
      When method post
      Then status 200
      And print &quot;Advert successfully activated&quot;
  
      Examples:
        | type          | category_id |
        | test1         | 163         |
        | test2         | 165         |
        | test3         | 167         |
        | test3         | 173         |
  </code></pre>
  <p>Then I execute a proper test located in <code>pricing-e2e.feature</code>:</p>
  <pre><code>  Background:
      * def result = call read('classpath:utilities/helper-random-data-js.feature@timestamp')
      * def timestamp = result.timestamp
      * print &quot;Current timestamp &quot; + timestamp
      * configure afterScenario =
        &quot;&quot;&quot;
        function(){
          var info = karate.info;
          karate.log('after', info.scenarioType + ':', info.scenarioName);
          karate.call('classpath:utilities/helper-create-test-data.feature@deactivate-advert', { caller: info.featureFileName });
        }
        &quot;&quot;&quot;
  
   @pricing
    Scenario: Payment events successfully received 
      * def adverts = call read('classpath:utilities/helper-create-test-data.feature@create-multiple-adverts')
  
      Given url payment_url
      And path 'bil/history/' + user_id
      And param startDate = timestamp
      When method get
      Then status 200
      And match response.data == '#[4]'
      Given url payment_url
      And path 'bil/site/' + user_id
      And param startDate = timestamp
      When method get
      Then status 200
  </code></pre>
  <p>And clean-up afterScenario located in <code>helper-create-test-data.feature</code></p>
  <pre><code>  @deactivate-advert
    Scenario: Deactivate an advert
      * def authentication = callonce read('classpath:utilities/helper-authenticate-user.feature')
      * def access_token = authentication.access_token
  
      Given url baseUrl
      And header Authorization = 'Bearer ' + access_token
      And path 'acc/ad/'+ advert_id + '/deactivate'
      And request { &quot;reason&quot;: {&quot;id&quot;: &quot;100&quot;, &quot;description&quot;: &quot;Some Reason&quot; } }
      When method post
      Then status 200
  </code></pre>
  <p>My questions are: how I can loop @deactivate-advert in <code>afterScenario</code> and how can I pass adverts_id into <code>afterScenario</code>? I should run this request 4 times because I created 4 items before.</p>