Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 4c4ae2a

Browse files
committed
Added missing Wait documentation
1 parent d552327 commit 4c4ae2a

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

documentation/chapters/waiting.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
[Home](../README.md)
22

33
# The Waits Utility Class
4-
The `Wait` utility class provides a fluent API for all kinds of wait operations. This includes waiting an exact amount of
5-
time and waiting for certain conditions with a timeout.
4+
The `Wait` utility class provides a fluent API for all kinds of wait operations.
5+
This includes waiting an exact amount of time and waiting for certain conditions
6+
with a timeout.
67

7-
## Examples
8+
**There are 3 distinct kinds of Wait operations:**
9+
1. Waiting an exact amount of time: `Wait.exactly(..)`
10+
2. Waiting until an object state is reached: `Wait.until(..)`
11+
3. Waiting until an object supplier return value's state is reached: `Wait.untilSupplied(..)`
12+
13+
**Examples**
814
```java
915
// waits 5 seconds
1016
Wait.exactly(5, TimeUnit.SECONDS);
@@ -16,12 +22,50 @@ Wait.exactly(150, TimeUnit.MILLISECONDS);
1622
Wait.exactly(1, TimeUnit.HOURS);
1723

1824
// waits until the hidden field is visible on the DOM - with default timeout
25+
PageFragment hiddenField = ...;
1926
Wait.until(hiddenField).is(visible());
2027

2128
// waits until the hidden field is visible on the DOM - with custom timeout
2229
Wait.withTimeoutOf(10, TimeUnit.SECONDS).until(hiddenField).is(visible());
30+
31+
// waits until the call to 'findMany(".foo")' returns a non empty list
32+
Wait.untilSupplied(() -> findMany(".foo")).is((foos) -> !foos.isEmpty());
2333
```
2434

35+
## Wait.exactly(...)
36+
37+
This is the most primitive wait operation.
38+
It allows to wait for a specific amount of time.
39+
That amount is specified by to parameters: the amount and the time unit.
40+
41+
The maximum precision for the wait operation is *milliseconds*.
42+
If any more precise unit is defined (e.g. nanoseconds), there will be no wait.
43+
44+
## Wait.until(..)
45+
46+
This kind of wait operation will take any object instance and allows for the
47+
definition of several conditions to be waited on in order.
48+
It is important to note that the conditions will always be evaluated against the
49+
initially specified instance!
50+
51+
In the above example you can see a command which will wait until a 'hidden' field
52+
is visible. This will work because the given object is a `PageFragment`. Since
53+
page fragments act as proxies for `WebElement` instances, which are not cached,
54+
the check on visibility can return a different result for each invocation.
55+
56+
But let's say, as an example, the given object is a list of page fragments and
57+
you want to wait until the list has a certain size. In this case the size of the
58+
list will never change unless it's contents is manipulated asynchronously.
59+
60+
In order to check something like this take a look at `Wait.untilSupplied(..)`.
61+
62+
## Wait.untilSupplied(..)
63+
64+
This kind of wait operation will take an object supplier as its parameter.
65+
The supplier is invoked every time a condition is checked.
66+
With this approach you can wait until a dynamic object - like a list of
67+
page fragments - has a certain state (e.g. size).
68+
2569
# Linked Documentation
2670

2771
- [Conditions](conditions.md)

0 commit comments

Comments
 (0)