Karate - Accessing certain value in an array element using a 'retry until' statement

19 Views Asked by At

I have an endpoint which returns this JSON response:

"challengeInstanceSummary": {
    "lastKnownDate": 12345690,
    "challengeInstances": [
      {
        "challengeInstanceId": "37d332467c",
        "displayName": "Downtime Measurement",
        "challengeStatus": "COMPLETED",
        "challengeSwitchGroup": "REPEATABLE",
        "points": 5,
        "pointsAwarded": null,
        "startDateInclusive": "2024-01-18",
        "endDateInclusive": "2024-01-18",
        "lastUpdated": 1705469419042,
        "challengeTemplateId": "80",
      }
   ]
}

The field challengeStatus is updated to COMPLETED 5 seconds after the previous step is executed since it goes through a series of services inthe background before it can update the value in this endpoint.

How can I use retry until to find this specific field in the array and retry till its finds the challengeStatus to be 'COMPLETED'

I had this code before but i read somewhere that JsonPath is not supported with retry until.

Given url BASEURL
    And path '/v2/mobilebackend/v2/member/me/summary'
    And param lastKnown = latest
    And retry until get[0] response.challengeInstanceSummary.challengeInstances[?(@.displayName=='Downtime Measurement')][0].challengeStatus == 'COMPLETED'
    When method get
    Then status 200
0

There are 0 best solutions below