-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Python ExpectedCondition "Or" "And" "Not" #7121
Comments
I could probably write & submit this PR; but I'd like guidance on whether such a change would be approved by the owners |
Python is a far more flexible language to write compared to Java, so I am not really on board with this. That being said if you do the work with tests, we can approve it since not everyone has the same mental model of working with code. Remember you can always write a complex condition as a function. Here's an example.
|
My thinking for suggesting at least the "OR" version was:
I don't know if #1 is at all a guiding principal for the project, which is why I asked :) Only peripherally related: I don't recognize attribute 'my_condition' in your example above. Is this a foo-style example? Of course if I were to submit a PR, I'd add some tests, which is why I am testing the water first. |
My example code is just a
|
Well Java DID implement it, so until they deprecate it, they have to live with their choices :) However, if the guiding voices say ExpectedConditions are in the sunset stage, and we should encourage individual python testers to roll their own conditional handling, then I'm not one to argue.! |
I don't want to discourage you from doing the work. If anything if you do it and it seems to have a good enough API then we can refine it. |
This was the class I made to implement 'OR'. (Ironically, we refactored and I don't actually need it) If you guys think it adds value to the project, I'd be happy to flesh it into a proper PR & submit it: class expected_or(object):
""" perform a logical 'OR' check on multiple expected conditions """
def __init__(self, *args):
self.expected_conditions = args
def __call__(self, driver):
for expected_condition in self.expected_conditions:
try:
result = expected_condition(driver)
if result:
return result
except NoSuchElementException:
pass In particular, I was toying with the idea of having the call raise an informative |
I actually expect this example to fail; the |
Replicates the functionality of Java's AND / OR / NOT expected conditions. Because of reserved word constraints in Python, these are named: OR: `any_of(*expected_condition)` AND: `all_of(*expected_condition)` NOT: `none_of(*expected_condition)` Each function takes an unlimited number of expected_conditions as arguments. Implements SeleniumHQ#7121
Replicates the functionality of Java's AND / OR / NOT expected conditions. Because of reserved word constraints in Python, these are named: OR: `any_of(*expected_condition)` AND: `all_of(*expected_condition)` NOT: `none_of(*expected_condition)` Each function takes an unlimited number of expected_conditions as arguments. Implements #7121
Replicates the functionality of Java's AND / OR / NOT expected conditions. Because of reserved word constraints in Python, these are named: OR: `any_of(*expected_condition)` AND: `all_of(*expected_condition)` NOT: `none_of(*expected_condition)` Each function takes an unlimited number of expected_conditions as arguments. Implements SeleniumHQ#7121
Replicates the functionality of Java's AND / OR / NOT expected conditions. Because of reserved word constraints in Python, these are named: OR: `any_of(*expected_condition)` AND: `all_of(*expected_condition)` NOT: `none_of(*expected_condition)` Each function takes an unlimited number of expected_conditions as arguments. Implements SeleniumHQ#7121
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
Copy the ExpectedConditions "Or", "And", and "Not" from the Java library to the Python library.
Motivation
Example
e.g. "Or": During A/B testing of a website, it is unknown which of 2 elements will be served every page load. The "Or" expected condition can ensure the test is unblocked as soon as either of them displays.
e.g. "Or": A user may or may not be shown a splash screen before the login-screen. Using "Or", a single test can begin execution as soon as it confirms that either a splash element or a login element is visible.
e.g. "And": A test may wish to confirm the visibility of multiple elements before continuing. (This functionality can be easily synthesized in test code, but using the "And" expected condition might create clearer code.)
e.g. "Not": A test may wish to wait for an element to disappear before continuing.
(This functionality can be easily synthesized in test code, AND it's often better to use the inverse ExpectedCondition, but using the "Not" expected condition might make clearer code.)
The text was updated successfully, but these errors were encountered: