如何在空手道中动态传递请求后参数以获取请求 [英] How to pass post request parameters dynamically to get request in Karate

查看:63
本文介绍了如何在空手道中动态传递请求后参数以获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

空手道中自动执行操作时,如何将一个API属性的值传递给另一个API?我有一个POST请求,提交后将在响应中生成一个ID,然后将该ID动态传递给即将到来的GET请求. 我已经尝试编写一种Java方法来进行读写,但是它不起作用.

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.

推荐答案

请暂时忘记Java,空手道与众不同!

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

我建议您这样做.使用ZIP版本: https://github.com/intuit/karate/wiki/ZIP -发布

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

有一个现成的测试users.feature.了解第12行如何从响应中提取第一个数组元素,然后我们需要在该元素(这是一个JSON对象)中使用id键.

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).

然后在第14行,它用于发出下一个请求.

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

请花一些时间阅读文档,这是值得的!

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

这篇关于如何在空手道中动态传递请求后参数以获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆