Skip to content
Martin Malina edited this page Mar 28, 2014 · 20 revisions

Waits are used in case when tests have to wait for some time, event or condition to be passed. Best practice is to use conditional waiting so test continues only in case when specific condition passed so developer can be sure that test is in proper state. Unfortunately there are situation when such a condition doesn't exist. In that case it's fine to create your own Condition. You should not pause test for some fixed time period but this is not recommended because it is not reliable solution.

Conditional waiting

RedDeer imlements these two main wait classes to perform conditional waiting. Optionally timeout for waiting can be specified using TimePeriod enum.

If timeout is not specified TimePeriod.NORMAL is used as default timeout value.

Both methods throws WaitTimeoutExpiredException when waiting expires for timeout

WaitUntil(WaitCondition condition); - waits until specified condition is fulfilled

WaitWhile (WaitCondition condition); - waits while specified condition is fulfilled

Usage

Waits until Shell with Text "Delete Server" is active with default timeout

new WaitUntil(new ShellWithTextIsActive("Delete Server"));

Waits while there are running jobs with TimePeriod.LONG timeout

new WaitWhile(new JobIsRunning(), TimePeriod.LONG);

In case default behavior of waiting routines is not sufficient then these constructors with more parameters can be used

WaitWhile (WaitCondition condition,TimePeriod timeout, boolean throwWaitTimeoutExpiredException); - waits while specified condition is fulfilled with specified timeout. If throwWaitTimeoutExpiredException is true and timeout expires WaitTimeoutExpiredException will be thrown

WaitUntil (WaitCondition condition,TimePeriod timeout, boolean throwWaitTimeoutExpiredException); - waits until specified condition is fulfilled with specified timeout. If throwWaitTimeoutExpiredException is true and timeout expires WaitTimeoutExpiredException will be thrown

Waiting for exact time period (not recommended)

To pause test for exact time period use static method sleep(millis) of class AbstractWait. It will put current thread to sleep state for specified time

Usage

Pauses test for 5 seconds

AbstractWait.sleep(5000);

TimePeriod

TimePeriod enum is used to specify common time periods. There are defined couple of enum values in seconds which should be sufficient enough for each purpose. In case that some special time period value is needed static method TimePeriod.getCustom(timeInSeconds) can be used to create TimePeriod.Custom enum with proper time period

Usage

Creates custom TimePeriod for 10 seconds long time period

TimePeriod.getCustom(10);

JBoss Red Deer - Quick Links

Clone this wiki locally