-1

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
Corey Snow
  • 225
  • 2
  • 15
  • when karate calls or switches to a new feature or scenario the HTTP builder is re-set. the solution for you is you need to re-define the URL. please read this part of the docs (section starting with: `Note that only variables and configuration settings will be passed`) https://github.com/karatelabs/karate#calling-other-feature-files | so if it was working differently before, that was a bug. if you disagree, please follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Apr 19 '22 at 04:39
  • Unfortunately for us we coded based on that "bug" and this situation would be all over our repository. I'm not exactly sure how to reset the path either. I've posted an image, and with the scenario executes the path variable isn't reset, it still comes out as concatenated, like "care/v1.1/account/MTYzODJAQDg=/call/add/care/v1.1/account/MTYzODJAQDg=/call/update". I've tried different ways of clearing it or using the url variable but nothing works. Any ideas? – Corey Snow Apr 19 '22 at 19:00
  • I can't look at images, and I still can't verify that this is a "bug" unless I get a working example. please follow the process I linked above, or figure out something that works for you. I have to say that you seem to have gone down the wrong path already: https://stackoverflow.com/a/54126724/143475 – Peter Thomas Apr 20 '22 at 02:20
  • I've cleaned the post and put the actual code in, which works perfectly fine on Karate 1.1.0. With Karate 1.2.0.RC6 the above code will fail at the point of the helper feature trying to do the post. If I remove the path from that feature, it will work, however the main feature will fail as the path comes concatenated. I keep getting "/care/v1.1/account/MTYzODJAQDg=/call/add/MTYzODJAQDg=/call/update". I've tried resetting the path after the call to the helper feature, same results. I've tried not using the path variable and using a different one, same results. – Corey Snow Apr 20 '22 at 19:24
  • it is basic courtesy to do what is called a minimal reproducible example. if you don't have the patience to do that, I'm sorry I can't help you: https://stackoverflow.com/help/minimal-reproducible-example – Peter Thomas Apr 21 '22 at 17:40
  • I've done that and submitted another issue, that clearly shows the problem. – Corey Snow Apr 22 '22 at 12:57

1 Answers1

0

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.

Corey Snow
  • 225
  • 2
  • 15