简体   繁体   English

重试直到 response.results[-1].trans.id.includes('TransactionID')

[英]Retry until response.results[-1].trans.id.includes('TransactionID')

Apologies if this has been answered before, I spent most of today looking and found some similar issues but nothing that answered my specific problem.抱歉,如果之前有人回答过这个问题,我今天大部分时间都在寻找并发现了一些类似的问题,但没有解决我的具体问题。

I am posting to a TransactionAPI with 'TransactionID'-> sleeping thread for 10 minutes (because this is ensures that the transaction posts in the next step) -> calling read api with我正在使用“TransactionID”发布到 TransactionAPI-> 休眠线程 10 分钟(因为这确保事务在下一步中发布)-> 调用读取 api

Then match response.results[*].trans.id contains TransactionID

this currently works, but sleep isn't great.. and I wanted to take full advantage of karate.这目前有效,但睡眠不是很好......我想充分利用空手道。 The [*] is because the new TransactionID appears in the final index of the returned array response. [*] 是因为新的 TransactionID 出现在返回的数组响应的最终索引中。 so the first time it calls the readAPI it gets an array of [5], and the new TransactionID will appear in [6] (and I couldn't figure out how to make it get array.length + 1 and wait for that one to appear)所以它第一次调用 readAPI 它得到一个 [5] 的数组,新的 TransactionID 将出现在 [6] 中(我不知道如何让它得到 array.length + 1 并等待那个出现)

Reading the responses here Karate framework retry until not working as expected and the linked ones inside i tried a few things:阅读此处的回复空手道框架重试,直到无法按预期工作,我尝试了一些内部链接:

And retry until response.results[-1].trans.id.includes('TransactionID')
And retry until response.results[(@.length-1)].trans.id.includes('TransactionID')

These return an error:这些返回错误:

org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:18 Expected an operand but found error

I tried the in-line javascript function mentioned in the above link, but could not get it to work either.我尝试了上面链接中提到的在线 javascript function,但也无法正常工作。

Javascript function mentioned: Javascript function 提到:

* def isValid = function(x){ return karate.match(x, { tokens: '##[_ > 0]' }).pass }
# ...
And retry until isValid(response)

So indexing to -1 will not work because that is JsonPath and not JavaScript.所以索引到-1将不起作用,因为那是 JsonPath 而不是 JavaScript。

Try this:尝试这个:

# set this by doing a call before if needed
* def prevLength = response.length
* def isValid = function(x){ return x.length > prevLength }
# ...
* retry until isValid(response)

My guess is that it is more than enough to achieve what you want.我的猜测是,这足以实现您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM