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
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. 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)
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 mentioned:
* 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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.