Sometimes it is necessary to have a timeout when verifying that a particular condition has been satisfied or the application has reached a particular state. for example, some UIs tests may involve asynchronous operations or time-consuming tasks.

The following code listing shows how to perform assertions using timeouts. In our example, we are going to assume that a JButton is enabled after calling a web service asynchronously.

In our example, if the JButton is not enabled after 10 seconds, the test will fail. The exception thrown will include the description of the Condition.