title: Reuse of feature files with retry until
body: <p>Having some stunning success with Karate. Working on end-to-end tests that use 'retry until' timeout on a GETs in order to wait for a specific parameter value within the response body. The parameter is expected to change state from A to B as data processing completes in the system under test. Interested to learn about patterns due to having standardised on a model of one <code>.feature</code> per API route. However this is only possible if we can parameterise the <code>retry until</code> terms. Otherwise this would mean writing multiple features to support different retry combinations.</p>
  
  <p>---Example of reusing <code>retry until</code> from comments---</p>
  
  <p>To maintain a single <code>get_notification_ref.feature</code> rather than one for each <code>until</code> combination, provide external <code>until</code> parameters in the call that can be used by the <code>retry</code> within the .feature.</p>
  
  <p><strong>Implementation that relies on specifying the until parameters inside the .feature file. End up with GET Notification feature file for each retry combination :</strong></p>
  
  <pre><code>Scenario: Get notification &amp; wait for status
     * call read('classpath:NotifyV1/get_notification_ref_wait_status.feature')
     .
     .
  
  Scenario: Get notification &amp; wait for status indicator colour
     * def expectedColour = 'GREEN'
     * call read('classpath:NotifyV1/get_notification_ref_wait_colour.feature')
  </code></pre>
  
  <p>get_notification_ref_wait_status.feature</p>
  
  <pre><code>Scenario: Get notification and wait on response status = 200
      Given path 'notification', notificationTypeReference
      And retry until responseStatus == 200
      When method get
      * def notificationResponse = $
  </code></pre>
  
  <p>get_notification_ref_wait_colour.feature</p>
  
  <pre><code>Scenario: Get notification and wait on response status = 200 and colour
      Given path 'notification', notificationTypeReference
      And retry until responseStatus == 200 &amp;&amp; response.statusColour == expectedColour
      When method get
      * def notificationResponse = $
  </code></pre>
  
  <p><strong>Implementation of the above that can handle parameterised retry until's  would look like this - note there is now only one GET Notification feature file:</strong></p>
  
  <pre><code>Scenario: Get notification &amp; wait for status 200
     * call read('classpath:NotifyV1/get_notification_ref.feature')
     .
     .
  
  Scenario: Get notification &amp; wait for status 200 and indicator colour
     * def UntilTerm = function(response){ return karate.match(response, '{statusColour: "GREEN"}').pass }
     * call read('classpath:NotifyV1/get_notification_ref.feature')
  </code></pre>
  
  <p>get_notification_ref.feature</p>
  
  <pre><code>Scenario: Get notification
      * def untilTerm = karate.get('UntilTerm') ? UntilTerm : function(response){ return true }
      * def untilStatus = karate.get('UntilStatus') ? UntilStatus : 200
      Given path 'notification', notificationTypeReference
      And retry until responseStatus == untilStatus &amp;&amp; untilTerm(response)
      When method get
      * def notificationResponse = $
      * karate.set('UntilTerm',null)
      * karate.set('UntilStatus',null)
  </code></pre>