Class DefaultWait<T>
An implementation of the IWait<T> interface that may have its timeout and polling interval configured on the fly.
public class DefaultWait<T> : IWait<T>
Type Parameters
TThe type of object on which the wait it to be applied.
- Inheritance
-
DefaultWait<T>
- Implements
-
IWait<T>
- Derived
- Inherited Members
Constructors
DefaultWait(T)
Initializes a new instance of the DefaultWait<T> class.
public DefaultWait(T input)
Parameters
inputTThe input value to pass to the evaluated conditions.
DefaultWait(T, IClock)
Initializes a new instance of the DefaultWait<T> class.
public DefaultWait(T input, IClock clock)
Parameters
inputTThe input value to pass to the evaluated conditions.
clockIClockThe clock to use when measuring the timeout.
Exceptions
- ArgumentNullException
If
clockorinputare null.
Properties
Message
Gets or sets the message to be displayed when time expires.
public string Message { get; set; }
Property Value
PollingInterval
Gets or sets how often the condition should be evaluated. The default timeout is 500 milliseconds.
public TimeSpan PollingInterval { get; set; }
Property Value
Timeout
Gets or sets how long to wait for the evaluated condition to be true. The default timeout is 500 milliseconds.
public TimeSpan Timeout { get; set; }
Property Value
Methods
IgnoreExceptionTypes(params Type[])
Configures this instance to ignore specific types of exceptions while waiting for a condition. Any exceptions not whitelisted will be allowed to propagate, terminating the wait.
public void IgnoreExceptionTypes(params Type[] exceptionTypes)
Parameters
exceptionTypesType[]The types of exceptions to ignore.
ThrowTimeoutException(string, Exception?)
Throws a WebDriverTimeoutException with the given message.
protected virtual void ThrowTimeoutException(string exceptionMessage, Exception? lastException)
Parameters
exceptionMessagestringThe message of the exception.
lastExceptionExceptionThe last exception thrown by the condition.
Remarks
This method may be overridden to throw an exception that is idiomatic for a particular test infrastructure.
Until<TResult>(Func<T, TResult?>)
Repeatedly applies this instance's input value to the given function until one of the following occurs:
- the function returns neither null nor false
- the function throws an exception that is not in the list of ignored exception types
- the timeout expires
public virtual TResult Until<TResult>(Func<T, TResult?> condition)
Parameters
conditionFunc<T, TResult>A delegate taking an object of type T as its parameter, and returning a TResult.
Returns
- TResult
The delegate's return value.
Type Parameters
TResultThe delegate's expected return type.
Until<TResult>(Func<T, TResult?>, CancellationToken)
Repeatedly applies this instance's input value to the given function until one of the following occurs:
- the function returns neither null nor false
- the function throws an exception that is not in the list of ignored exception types
- the timeout expires
public virtual TResult Until<TResult>(Func<T, TResult?> condition, CancellationToken token)
Parameters
conditionFunc<T, TResult>A delegate taking an object of type T as its parameter, and returning a TResult.
tokenCancellationTokenA cancellation token that can be used to cancel the wait.
Returns
- TResult
The delegate's return value.
Type Parameters
TResultThe delegate's expected return type.