Search code examples
jmetercontroller

Need to execute the api only once once the response has the correct value in jmeter


For the ride bookin app i need to stop the execution of 'End Ride' api once i receive the status as 'COMPLETED' in response.Currently I am using while controller but that enters infinite loop. API Response: {"id":3820,"status":"COMPLETED","rider":{"id":2019,"firstname":"test","lastname":"rider","phoneNumber":"9000000124","email":"[email protected]","rating":5.0,"user":{},"fullName":"test rider"},"startLocationLat":36.10805389068134,"startLocationLong":-115.16570490025539,"endLocationLat":36.10805389068134,"endLocationLong":-115.16570490025539,"startAddress":"73 South Martin Luther King Boulevard","endAddress":"920 West Bonanza Road","start":{"address":"73 South Martin Luther King Boulevard","zipCode":"89106"},"end":{"address":"920 West Bonanza Road"},"surgeFactor":1.00,"driverPayment":"4.00","requestedCarType":{"title":"STANDARD","carCategory":"REGULAR","plainIconUrl":"https://media.ride-vegas.com/regular.png","configuration":"{"skipRideAuthorization": false}"},"requestedDriverTypes":[],"freeCreditCharged":"0.00"}

This is the JSON and it is validated correctly over https://jsonlint.com/. I need to execute the END RIDE API only once when the status is COMPLETED .Is there any way wherein i can do so?


Solution

    1. Put the request which returns this JSON under the While Controller

    2. Add JSON Extractor as a child of the request and configure it as follows:

      enter image description here

    3. Use the following __jexl3() function as While Controller's condition:

      ${__jexl3("${status}" != "COMPLETED",)}
      

      enter image description here

    4. That's it, While Controller will run it's child(ren) until status variable won't become COMPLETED