Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Improve docs and add support for specifying ElementPoller directly
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepryde committed Oct 5, 2020
1 parent b8a110b commit 66ccc81
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "thirtyfour_query"
version = "0.4.0"
version = "0.4.1"
authors = ["Steve Pryde <steve@stevepryde.com>"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Advanced element query interface for thirtyfour crate"
description = "Advanced element query interface for the thirtyfour crate"
homepage = "https://github.com/stevepryde/thirtyfour_query"
repository = "https://github.com/stevepryde/thirtyfour_query"
documentation = "https://docs.rs/thirtyfour_query"
Expand Down
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

Advanced element query interface for the thirtyfour crate.

## Experimental
## Usage

First, set the default polling behaviour:
```rust
// Disable implicit timeout in order to use new query interface.
driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;

This crate is experimental and expected to have breaking changes often.
let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::from_millis(500));
driver.config_mut().set("ElementPoller", poller)?;
```

## Usage
Other ElementPoller options are also available, such as NoWait and NumTriesWithInterval.
These can be overridden on a per-query basis as needed.

With the new query interface you can do things like:
Now, using the query interface you can do things like:

```rust
let elem_text =
Expand All @@ -30,17 +38,6 @@ and you'll get a Vec instead. This will never return an empty Vec. If either fir
don't match anything, you'll get `WebDriverError::NoSuchElement` instead.
The error message will show the selectors used.

To set up default polling for all elements, do this:
```rust
// Disable implicit timeout in order to use new query interface.
driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;

let poller = ElementPoller::Time(Duration::new(20, 0), Duration::from_millis(500));
driver.config_mut().set("ElementPoller", poller)?;
```

Other ElementPoller options are also available, such as NoWait and NumTries.

## LICENSE

This work is dual-licensed under MIT or Apache 2.0.
Expand Down
28 changes: 12 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
//!
//! See examples for more details.
//!
//! ## Experimental
//! ## Usage
//!
//! This crate is still experimental and expected to have breaking changes often, however
//! the basic interface is working.
//! First, set the default polling behaviour:
//! ```no_run
//! // Disable implicit timeout in order to use new query interface.
//! driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;
//!
//! ## Usage
//! let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::from_millis(500));
//! driver.config_mut().set("ElementPoller", poller)?;
//! ```
//!
//! Other ElementPoller options are also available, such as NoWait and NumTriesWithInterval.
//! These can be overridden on a per-query basis as needed.
//!
//! With the new query interface you can do things like:
//! Now, using the query interface you can do things like:
//!
//! ```no_run
//! let elem_text =
Expand All @@ -31,15 +38,4 @@
//! don't match anything, you'll get `WebDriverError::NoSuchElement` instead.
//! The error message will show the selectors used.
//!
//! To set up default polling for all elements, do this:
//! ```no_run
//! // Disable implicit timeout in order to use new query interface.
//! driver.set_implicit_wait_timeout(Duration::new(0, 0)).await?;
//!
//! let poller = ElementPoller::TimeoutWithInterval(Duration::new(20, 0), Duration::from_millis(500));
//! driver.config_mut().set("ElementPoller", poller)?;
//! ```
//!
//! Other ElementPoller options are also available, such as NoWait and NumTries.
pub mod query;
17 changes: 11 additions & 6 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,24 @@ impl<'a> ElementQuery<'a> {
}
}

/// Use the specified ElementPoller for this ElementQuery.
/// This will not affect the default ElementPoller used for other queries.
pub fn with_poller(mut self, poller: ElementPoller) -> Self {
self.poller = poller;
self
}

/// Force this ElementQuery to wait for the specified timeout, polling once
/// after each interval. This will override the poller for this
/// ElementQuery only.
pub fn wait(mut self, timeout: Duration, interval: Duration) -> Self {
self.poller = ElementPoller::TimeoutWithInterval(timeout, interval);
self
pub fn wait(self, timeout: Duration, interval: Duration) -> Self {
self.with_poller(ElementPoller::TimeoutWithInterval(timeout, interval))
}

/// Force this ElementQuery to not wait for the specified condition(s).
/// This will override the poller for this ElementQuery only.
pub fn nowait(mut self) -> Self {
self.poller = ElementPoller::NoWait;
self
pub fn nowait(self) -> Self {
self.with_poller(ElementPoller::NoWait)
}

/// Add the specified selector to this ElementQuery. Callers should use
Expand Down

0 comments on commit 66ccc81

Please sign in to comment.