Awaitility: how to perform post-actions if a condition failed?

1.7k Views Asked by At

In Awaitility, how can I perform a post-action if a condition I'm waiting for fails? For example, collecting additional information, do some logging, or throwing an exception?

The only way I've found is to use a try-catch:

try {
  Awaitility.await().until(myCondition)
} catch (Exception ex) {
  // post actions
}

Is there a more Awaitility-like way of doing this?

1

There are 1 best solutions below

0
Johan On

You can use a condition evaluation listener:

await()
        .conditionEvaluationListener(condition -> {
            if (condition.getRemainingTimeInMS() <= 0) {
                // Do stuff!
            }
        })
        .until(myCondition)