Expand description

Allow to wait for conditions.

Sometimes it is necessary to wait for a browser to achieve a certain state. For example, navigating to a page may be take bit of time. And the time may vary between different environments and test runs. Static delays can work around this issue, but also prolong the test runs unnecessarily. Longer delays have less flaky tests, but even more unnecessary wait time.

To wait as optimal as possible, you can use asynchronous wait operations, which periodically check for the expected state, re-try if necessary, but also fail after a certain time and still allow you to fail the test. Allow for longer grace periods, and only spending the time waiting when necessary.

Basic usage

By default all wait operations will time-out after 30 seconds and will re-check every 250 milliseconds. You can configure this using the Wait::at_most and Wait::every methods or use Wait::forever to wait indefinitely.

Once configured, you can start waiting on some condition by using the Wait::for_* methods. For example:

// -- snip wrapper code --
let button = client.wait().for_element(Locator::Css(
    r#"a.button-download[href="/learn/get-started"]"#,
)).await?;
// -- snip wrapper code --

Error handling

When a wait operation times out, it will return a CmdError::WaitTimeout. When a wait condition check returns an error, the wait operation will be aborted, and the error returned.

Structs

Used for setting up a wait operation on the client.