How to pass post request parameters dynamically to get request in Karate

[亡魂溺海] 提交于 2020-05-31 05:41:21

问题


How do I pass a value of one API attribute to another API while automating in Karate? I have a POST request which when submitted will generate an id in the response, and I pass that id dynamically to the upcoming GET request. I have already tried writing an Java method to read and write but it doesn't work.


回答1:


Please forget about Java for a moment, Karate is very different !

For you I suggest you do this. Use the ZIP Release: https://github.com/intuit/karate/wiki/ZIP-Release

There is a ready-made test users.feature. See how line 12 extracts the first array element from the response and then we need to use the id key out of that element (which is a JSON object).

And then on line 14, it is used to make the next request.

Please spend some time reading the documentation, it is worth it !



来源:https://stackoverflow.com/questions/60364230/how-to-pass-post-request-parameters-dynamically-to-get-request-in-karate

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