'How do use the same variable in background and feature being called

With Karate 1.1.0, you could define a variable in the background, ex "* path = 'www.google.ca', call a "helper" feature at the top of of a scenario, which was using the same variable name inside it, then later in your scenario use the same variable again. Ex., helper feature would have "* path = 'www.google.ca' in it's 1 and only scenario, which would say something like "Given path '/help.html'". Then in your main feature, after you have called the helper feature you would use the variable again, something like "Given path '/fun.html'". When everything ran it would be fine, the helper feature would point to it's path and the main feature would point to it's path.

Now with Karate 1.2.0.RC6, I don't have to declare path in the helper feature, but with that change the path is being concatenated in the main feature/scenario. So when the scenario executes, it calls the helper feature fine, but then instead of it's path being "www.google.ca/fun.html" it comes "www.google.ca/help.html/fun.html". Any ideas why or better how to resolve it?

example

Here's the actual code:

Feature: Update calls on an account

Background:

* url url

* header Authorization = token

* path 'care/v1.1/account/'

Scenario: theScenario

    * def fullResponse = call read('init/movein_ADD.feature') { payloadFilename: 'data/account_id_call_ADD_MOVEIN_No_GovtId.json'}
    * def updatePayload = read('data/account_id_call_add_MOVEIN_Both_GovtId.json')
    * set updatePayload.callNumber = fullResponse.response.callNumber
    * set updatePayload.id = fullResponse.response.id  
    * set updatePayload.orderNumber = fullResponse.response.orderNumber  
    * set updatePayload.stagedServices = null
    
    * header Accept = json
    * header Content-Type = json
Given path ENCODE('16382-8') + '/call/update'
  And request updatePayload 
 When method POST
 Then status 200

Helper feature:

@ignore

Feature: Helper feature file to create Move-In Service order request

Scenario: helper Scenario

        * url url
        * path 'care/v1.1/account/'
    * def payload = read(payloadFilename)

    #set up request and execute
    * header Accept = json
    * header Content-Type = json
 Given path 'MTYzODJAQDg=/call/add'
  And request payload
 When method POST
 Then status 200


Solution 1:[1]

The answer, change to declare a variable in the background of the main feature file, set the path to that variable in the helper feature scenario and again the main feature scenario right after the call to the helper feature file has worked. Going to cause some big refactoring on our part based on this change.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corey Snow