如何与重试一起创建动态路径组件,直到 [英] How to create dynamic path component in conjunction with retry until
问题描述
我有一个用例,需要首先调用API以获得ID列表.从该响应中选择一个随机ID.接下来,我调用第二个API,该API使用随机ID作为路径中的组件.
I have a use-case where I need to first call an API to get a list of ID's. From this response a random ID is chosen. Next I call a 2nd API which uses the random ID as a component in the path.
第二个API调用有可能返回空响应,因此我想使用retry until
,但每次重试迭代的路径中使用不同的随机ID.
It's possible the 2nd API call can return an empty response, therefore I want to utilize retry until
but use a different random ID in the path per retry iteration.
我尝试了几件事:
首先在路径中内联" JS函数以获取随机ID:
First "in-lining" the JS function in the path to get a random ID:
Given path firstPart, myGetRandomId(idList), lastPart
And retry until response.length > 1
第二,尝试将JS函数放在Examples:
中作为Scenario Outline:
Second, tried putting the JS function in a Examples:
as part of a Scenario Outline:
Given path firstPart, <ID>, lastPart
And retry until response.length > 1
Examples:
| ID |
| myGetRandomId(idList) |
我不知道的一般问题是如何使用这种内联"方法来评估JS函数.
The general issue I can't figure out is how to get the JS function to evaluate in either of this "in-line" kind of approaches.
对想法/建议表示赞赏.
And ideas/suggestions appreciated.
推荐答案
空手道retry until
的工作方式是它将按原样重播请求 ,而您不能修改它.
The way that the Karate retry until
works is that it will re-play the request as-is and you can't modify it.
因此,您必须采用其他方法.使用JS循环.在演示中看这个例子:
So you have to take a different approach. Use a JS loop. Look at this example in the demos:
https ://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/polling/polling.feature
这篇关于如何与重试一起创建动态路径组件,直到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!