org.jboss.test.selenium.waiting
Class Wait

java.lang.Object
  extended by org.jboss.test.selenium.waiting.Wait

public class Wait
extends java.lang.Object

Implementation of waiting to satisfy condition.

This class constructs instances of Waiting by factory methods but provides its functionality (defaulted waiting) by static method until.

Other factories (getDefault(), timeout(long), interval(long)) serves as simplified way to build new configured instance, which can simple run waiting loop.

Class is intended to be used like these:

  1. direct waiting loop

     Wait.until(new Condition()) {
         public boolean isTrue() {
             return ...;
               }
     }
     
  2. direct waiting loop with parameters

     Wait.interval(100).timeout(3000).until(new Not()) {
         public boolean not() {
             return ...;
         }
     }
     
  3. save settings and run configured wait loop

     final String locator1 = "...";
     final String locator2 = "...";
     
     ...
     
     Condition locatorsEqual = new Condition() {
         public boolean isTrue() {
             return selenium.equals(locator1, locator2);
         }
     };
     
     Waiting waitResponse = Wait.interval(1000).timeout(30000);
                            
     ...
     
     waitResponse.until(locatorsEqual); // some usage
     
     ...
     
     waitResponse.until(locatorsEqual); // other usage
     

Version:
$Revision$
Author:
Lukas Fryc

Nested Class Summary
static class Wait.Waiting
          Class intented to construct by factories in Wait class.
 
Field Summary
static long DEFAULT_INTERVAL
          Default waiting interval
static long DEFAULT_TIMEOUT
          Default timeout of waiting
 
Method Summary
static Wait.Waiting dontFail()
          Constructs preset instance of waiting (@see Waiting) with no failure.
static Wait.Waiting failWith(java.lang.CharSequence failureMessage, java.lang.Object... args)
          Constructs preset instance of waiting (@see Waiting) with given failure message parametrized by given objects If failure is set to null, timeout will not result to failure!
static Wait.Waiting failWith(java.lang.Object failureSubject)
          Constructs preset instance of waiting (@see Waiting) with given subject of failure.
static Wait.Waiting getDefault()
          Constructs default preset instance of waiting (@see Waiting).
static Wait.Waiting interval(long interval)
          Constructs preset instance of waiting (@see Waiting) with given interval.
static Wait.Waiting noDelay()
          Constructs preset instance of waiting (@see Waiting) with no delay by interval between start waiting and first test for conditions.
static Wait.Waiting timeout(long timeout)
          Constructs preset instance of waiting (@see Waiting) with given timeout.
static void until(Condition condition)
          Stars loop waiting to satisfy condition with default timeout and interval.
static void waitFor(long timeoutInMilis)
          Will wait for specified amount of time.
static
<T> void
waitForChange(T oldValue, Retrieve<T> retrieve)
          Waits until Retrieve's implementation doesn't retrieve value other than oldValue.
static
<T> T
waitForChangeAndReturn(T oldValue, Retrieve<T> retrieve)
          Waits until Retrieve's implementation doesn't retrieve value other than oldValue and this new value returns.
static void waitForTimeout()
          Will wait for default amount of time.
static Wait.Waiting withDelay(boolean isDelayed)
          Constructs preset instance of waiting (@see Waiting) and set that testing condition should or shouldn't be delayed of one interval after the start of waiting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INTERVAL

public static final long DEFAULT_INTERVAL
Default waiting interval

See Also:
Constant Field Values

DEFAULT_TIMEOUT

public static final long DEFAULT_TIMEOUT
Default timeout of waiting

See Also:
Constant Field Values
Method Detail

getDefault

public static Wait.Waiting getDefault()
Constructs default preset instance of waiting (@see Waiting).

Returns:
default Waiting instance

interval

public static Wait.Waiting interval(long interval)
Constructs preset instance of waiting (@see Waiting) with given interval.

Parameters:
interval - in miliseconds that will be preset to Waiting
Returns:
Waiting instance initialized with given interval

timeout

public static Wait.Waiting timeout(long timeout)
Constructs preset instance of waiting (@see Waiting) with given timeout.

Parameters:
timeout - in miliseconds that will be preset to Waiting
Returns:
Waiting instance initialized with given timeout

failWith

public static Wait.Waiting failWith(java.lang.Object failureSubject)
Constructs preset instance of waiting (@see Waiting) with given subject of failure. It can be a Throwable (in that case it will be used as cause) or it can be any other object (it will be converted to String and used as exception message).

Parameters:
failureSubject - Throwable (used in cause) or any other object (will be converted to expection message by its string value)
Returns:
Waiting instance initialized with given failure subject

failWith

public static Wait.Waiting failWith(java.lang.CharSequence failureMessage,
                                    java.lang.Object... args)
Constructs preset instance of waiting (@see Waiting) with given failure message parametrized by given objects If failure is set to null, timeout will not result to failure!

Parameters:
failureMessage - character sequence that will be used as message of exception thrown in case of waiting timeout or null if waiting timeout shouldn't result to failure
args - arguments to failureMessage which will be use to parametrization of failureMessage
Returns:
Waiting instance initialized with given failureMessage and arguments

dontFail

public static Wait.Waiting dontFail()
Constructs preset instance of waiting (@see Waiting) with no failure. Waiting timeout with this preset dont result to failure!

Returns:
Waiting instance initialized with no failure

noDelay

public static Wait.Waiting noDelay()
Constructs preset instance of waiting (@see Waiting) with no delay by interval between start waiting and first test for conditions.

Returns:
Waiting instance initialized with no delay

withDelay

public static Wait.Waiting withDelay(boolean isDelayed)
Constructs preset instance of waiting (@see Waiting) and set that testing condition should or shouldn't be delayed of one interval after the start of waiting.

Parameters:
isDelayed - true if condition testing should be delayed; false otherwise
Returns:
Waiting instance initialized with delay if isDelayed is set to true; with no delay otherwise

waitForTimeout

public static void waitForTimeout()
Will wait for default amount of time. Default timeout specified in Wait.DEFAULT_TIMEOUT


waitForChange

public static <T> void waitForChange(T oldValue,
                                     Retrieve<T> retrieve)
Waits until Retrieve's implementation doesn't retrieve value other than oldValue.

Type Parameters:
T - type of value what we are waiting for change
Parameters:
oldValue - value that we are waiting for change
retrieve - implementation of retrieving actual value

waitForChangeAndReturn

public static <T> T waitForChangeAndReturn(T oldValue,
                                           Retrieve<T> retrieve)
Waits until Retrieve's implementation doesn't retrieve value other than oldValue and this new value returns.

Type Parameters:
T - type of value what we are waiting for change
Parameters:
oldValue - value that we are waiting for change
retrieve - implementation of retrieving actual value
Returns:
new retrieved value

waitFor

public static void waitFor(long timeoutInMilis)
Will wait for specified amount of time. Timeout is specified in miliseconds

Parameters:
timeoutInMilis - time to wait in miliseconds

until

public static void until(Condition condition)
Stars loop waiting to satisfy condition with default timeout and interval.

Parameters:
condition - what wait for to be satisfied


Copyright © 2010. All Rights Reserved.