title: Karate - Having multiple 'When's in single scenario
body: <p>I have a scenario where there are multiple steps/ REST operations needs to be run to complete one process.</p>
  
  <p>Each REST operation needs to have authorization username and password. I have provided this in <strong>Background</strong> session. This is how my present feature looks like.</p>
  
  <pre><code>Feature: Adding to cart
  
    Background: 
      * url 'https://soa-mp-rmsk-someurl.com'
      * header agent_uid = 'AUTO_TST'
      * configure ssl = true
      * header Authorization = call read('classpath:Project/JSFiles/auth.js') { username: 'ABC', password: '123' }
      * configure logPrettyResponse = true
      * configure logPrettyRequest = true
  
    Scenario: Find available mobiles
      Given path '/v1/available-mobiles'
      When method get
      Then status 200
      * def mobile = response.iPhoneXSMax
  
    # Add a mobile to cart
      Given path '/v1/mobiles/'+mobile+'/add
      And request {name: 'iPhoneXSMax'}
      When method put
      Then status 200
  </code></pre>
  
  <p>Now this throws error saying that <code>"faultstring": "Authentication challenge issued"</code>.</p>
  
  <p>I can group them into different scenarios so that they call <code>header authorization</code> every time which results in successful run; I have tried this as well. Works for me. But i don't think its a good practice to group these steps in different scenarios as they literally makes a single scenario. How can i overcome this error? Or should i go and distribute them in different scenarios?</p>
  
  <p><a href="https://automationpanda.com/2018/02/03/are-gherkin-scenarios-with-multiple-when-then-pairs-okay/" rel="nofollow noreferrer">https://automationpanda.com/2018/02/03/are-gherkin-scenarios-with-multiple-when-then-pairs-okay/</a></p>
  
  <p><strong>EDIT-1</strong>
  This is how i tried to add configure headers for Authorization details; I was not able to fully understand this, could you please help?</p>
  
  <p><strong>headers.js</strong></p>
  
  <pre><code>function fn() {
        var username = karate.get('username');
        var password = karate.get('password');
        if (username &amp;&amp; password) {
          return { 
              Authorization: username + password
          };
        } else {
          return {};
        }
      }
  </code></pre>
  
  <p>And i called it in feature background like this; but didn't worked.</p>
  
  <pre><code>* configure headers = read('classpath:headers.js')
  * def username = 'ABC'
  * def password = '123'
  </code></pre>