I'm using Karate framework with JUnit.
Using this feature:
Given path 'save_token'
And request
"""
{
"token": "test_token"
}
"""
And retry until response.tokens ==
"""
[
"test_token"
]
"""
When method POST
I'm having this exception:
java.lang.ArrayIndexOutOfBoundsException: 1
at com.intuit.karate.core.MethodMatch.convertArgs(MethodMatch.java:60)
at com.intuit.karate.core.Engine.executeStep(Engine.java:141)
at com.intuit.karate.core.ScenarioExecutionUnit.execute(ScenarioExecutionUnit.java:171)
When response.tokens list is empty:
{
"tokens": []
}
I don't understand why == does not work in this case (it should return false, and keep retrying).
Thanks in advance!
The
retry until
expression has to be pure JavaScript and the special Karate match keywords such ascontains
are not supported, and you can't do a "deep equals" like how you are trying, as that also is not possible in JS.So if your response is
{ "tokens": [ "value1" ] }
, you can do this:Or:
To experiment, you can try expressions like this:
At run time, you can use JS to take care of conditions when the response is not yet ready while polling:
EDIT: actually a more elegant way to do the above is shown below, because
karate.get()
gracefully handles a JS or JsonPath evaluation failure and returnsnull
:Or if you are dealing with XML, you can use the
karate.xmlPath()
API:And if you really want to use the power of Karate's
match
syntax, you can use the JS API:Note that if you have more complex logic, you can always wrap it into a re-usable function:
Finally if none of the above works, you can always switch to a custom polling routine:
polling.feature