How to create dynamic path component in conjunction with retry until

感情迁移 提交于 2021-02-05 08:59:06

问题


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.

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.

I've tried a couple of things:

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

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

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.


回答1:


The way that the Karate retry until works is that it will re-play the request as-is and you can't modify it.

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



来源:https://stackoverflow.com/questions/60012242/how-to-create-dynamic-path-component-in-conjunction-with-retry-until

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