This project contains libraries that can be used to wait on code execution until it finishes successfully. This can be helpful for instance when writing acceptance tests that need to wait for some JavaScript on a page to finish executing before an element can be found or interacted with.
This is the core library that contains the Waiter
that is used to repeatedly execute code until it succeeds or times out. The definition of success can be set with
Options
.
import shiver.me.timbers.waiting.Waiter;
import shiver.me.timbers.waiting.Options;
import shiver.me.timbers.waiting.Until;
class Examples {
public void all() {
new Waiter(new Options().willWaitForTrue(true)).wait(new Until<Boolean>() {
private Exception exception;
private boolean hasRun = false;
public Boolean success() throws Throwable {
System.out.println("Run this code thrice.");
if (exception == null) {
throw (exception = new Exception());
}
return hasRun || !(hasRun = true);
}
});
}
}
With this library it is possible to wait on methods and classes by simply applying the '@Wait' annotation.
import shiver.me.timbers.waiting.Wait;
class Examples {
@Wait
class WaitOnAllMethods {
public void one() {
}
public void two() {
}
}
class WaitOnOneMethod {
@Wait
public void one() {
}
public void two() {
}
}
}
This library allows the global configuration of all Waiter
s with Spring properties.