-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[draft] Create wait structure #95
base: main
Are you sure you want to change the base?
Conversation
Ok(v) => break Ok(v), | ||
Err(error::CmdError::NoSuchElement(_)) => {} | ||
Err(e) => break Err(e), | ||
fn closure( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your problem likely stems from trying to define a fn closure
here. If you just put this code directly into the move |client| {}
below, I think you should be fine, and not need the clone?
} | ||
} | ||
|
||
const DEFAULT_TIMEOUT: std::time::Duration = std::time::Duration::from_millis(500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, by default, this method should never time out. The user asked us to wait indefinitely. If the user wants a timeout, they can do so by wrapping the returned future in a tokio::time::timeout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that you're speaking about changes in wait_for
here's you are right.
It's just a method which I chose to demonstrate the Wait
😄 and didn't noticed that I break it's logic 😄
Probably there could be introduced a new type WaitForever which would do just loop
. And after we could amalgamate these by a trait Waiter
which has a method until
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My argument was more that all you need is the ability to wait forever. If the user wants to stop waiting before the action succeeds, they can just wrap the future in tokio::time::timeout
:)
} | ||
} | ||
|
||
pub(crate) async fn until<F, FF, R>(&mut self, condition: F) -> Result<R, Duration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole Wait
type only really makes sense if users can define their own waiters, which would mean making this method pub
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was meant to be a base
implementation on which could be piled different peaces. But I didn't decide at the time it created for users or for lib itself so it just get a smallest scope I was considering.
It may worth it.
Hopefully the comments above help a little! I'm still not quite sure what adding this kind of |
I consider it's useful to have an abstractions For example let is_displayed = match element.attr("style").await? {
Some(style) if !style.contains("display: none;") => true,
None => true,
_ => false,
};
let is_enabled = match element.attr("disabled").await? {
Some(..) => false,
_ => true,
};
is_displayed && is_enabled The timer logic could be shifted to |
By the way what do you think about adding |
I guess my argument is more that those methods should only be implemented in their "one shot" version, so Now, it might be useful to provide something like a
I'm not sure I follow? Are you talking about parsing the |
Overview
Hello @jonhoo, I've tried to improve
*_wait
methods by creating aWait
structure which will allow to create it's ownrules
.The design is primarily inspired by C# driver.
Here's an example how it's done in C#.
And here this example with new
Wait
structure.We also could create a set of predefined methods
wait_for_visible
,wait_for_not_present
etc...link #27
link #85
link #93
Implementation
Sadly I didn't figure out a way to support closures properly. There's an issue with lifetimes therefore in changed
wait_for_find
method I created a nested function which takes a cloned Client. That's only because of my incompetence here otherwise it had to be as simple as in example. I've not resolved the issue yet and decided to send the draft with believe that you may know some of pathways to resolve this issue 😄 .As I understand right now
wait_for
method may have the same issue?If you try to use
&mut Client
in closure there will be a problem occurred.