path variable initialized in the background gets reset for some scenarios

[亡魂溺海] 提交于 2021-01-28 13:34:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!