Search code examples
karate

retry until with response arrays


Hoping someone can tell me what I'm doing wrong here. I see the value for foo in the response with each retry. Oddly, once it a while it will pass. No issues if I remove the retry until and evaluate it after making the call.

* def bar = "baz"

* retry until response[0].foo.bar == bar

response = 
[
  {
    "foo": {
      "bar": "baz"
    }
  }
]

[Thread-0] WARN com.intuit.karate - retry condition evaluation failed: js failed: 01: response[0].foo.bar == bar org.graalvm.polyglot.PolyglotException: TypeError: Cannot read property "foo" from undefined .:program(Unnamed:1)


Solution

  • Try:

    * retry until response && response.length && response[0].foo.bar == bar
    

    Add more "checks" like this as needed as there may be an empty array initially etc.

    Refer this also: https://stackoverflow.com/a/55823180/143475