1

We have a main feature file with about 80 scenarios mixed of testing POST and GET request, and some of them called auxiliary feature files that get data from different REST endpoints. In the main feature file, we have Background section where we set a path variable. I noticed that this path variable gets reset (just empty) for some scenarios. I'm not sure what causes this, but one common thing they have are that they are all POST requests. To resolve this problem, I'm doing this :

Given path 'part1/version/part2/' + ENCRYPT('123')

even though I have the following line in background section

* path 'part1/version/part2/'

I'm curious what causes karate to reset path variable.

KMC
  • 1,677
  • 3
  • 26
  • 55

1 Answers1

1

Yes, this is by design. The path is always cleared after an HTTP request. This is to make handling REST-ful URL-s easier. In fact the "hello world" example itself uses this to its advantage.

If you want the URL to not reset, include it in the url.

* url myBaseUrl + '/part1/version/part2'

Described in the docs: https://github.com/intuit/karate#path

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Isn't variable inside Background section supposed to be reinitialized for each scenario? That's what it said in the Script Structure section of the documentation - https://github.com/intuit/karate. That fact that I have initialized path variable with a particular value inside the Background scope, I was expecting it to be reinitialized with that value for each scenario. – KMC Apr 28 '20 at 15:37
  • @KMC `path` is not a variable – Peter Thomas Apr 28 '20 at 15:37
  • regardless of variable or not, are you saying that path initialization line gets called only once for all scenarios? – KMC Apr 28 '20 at 15:41
  • 1
    @KMC all I'm saying is that a `Background` is run before any `Scenario` and a `path` will modify any `url` that came before it. now look at your feature. if you are still stuck, maybe there's a bug :) so follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Apr 28 '20 at 15:44