问题
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.
回答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
来源:https://stackoverflow.com/questions/61480092/path-variable-initialized-in-the-background-gets-reset-for-some-scenarios