Repeating Endpoint Execution

One of the important requirements in testing is to repeat the endpoint execution in a loop either for n times or based on some condition. For such cases, we have the repeat and related keys in Vibranium.

repeat [integer]

repeat is used when you want the API execution to repeat n times. Whenever you add this key, the endpoint will be repeated for the mentioned amount of times and the response will be returned as an array of responses. To explain this in a simple way, let's say we have the endpoint test definition as follows:

{
    "name": "api_name",
    "url": "/api/v1/users/{userId}",
    // rest of the test
}

And let's say the expected response for this API is an object as follows:

{
    "id": "some_unique_id",
    "name": "User Name",
    // ... rest of the reponse
}

Now when I add "repeat": 10 to the endpoint test definition, the response becomes

[
    {
        "id": "some_unique_id1",
        "name": "User Name 1",
        // ... rest of the reponse
    }, {
        "id": "some_unique_id2",
        "name": "User Name 2",
        // ... rest of the reponse
    },
    // 8 more objects
]

So when you use the response in some other API or in assertions, make sure you pick the value from the array instead of the actual object

repeat-until [object]

repeat-until is used whenever you want the endpoint execution to repeat based on some condition. The value for this key is an object, that follows the same structure as the expect keyword. So if you want to repeat until the response status is 200 and till the status key in response is 'SUCCESS', then the syntax should be:

"repeat-until": {
    "status": 200,
    "response": {
        "status should be 'SUCCESS'": "'{response.status}' === 'SUCCESS'"
    }
}

As mentioned above, the response will be in an array format, containing the response each time the endpoint was executed.

repeat-delay [integer]

repeat-delay is used to control the delay between each repetition. It is specified in milliseconds. For example "repeat-delay": 5000 for repeating every 5 seconds.