-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement logical expected conditions in Python
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
- Loading branch information
1 parent
b31f2e0
commit ead2a2c
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
py/test/selenium/webdriver/support/expected_conditions_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import pytest | ||
|
||
from selenium.common.exceptions import TimeoutException | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.remote.webelement import WebElement | ||
|
||
|
||
def test_any_of_true(driver, pages): | ||
pages.load("simpleTest.html") | ||
WebDriverWait(driver, 0.1).until(EC.any_of( | ||
EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) | ||
|
||
|
||
def test_any_of_false(driver, pages): | ||
pages.load("simpleTest.html") | ||
with pytest.raises(TimeoutException): | ||
WebDriverWait(driver, 0.1).until(EC.any_of( | ||
EC.title_is("Nope"), EC.title_is("Still Nope"))) | ||
|
||
|
||
def test_all_of_true(driver, pages): | ||
pages.load("simpleTest.html") | ||
results = WebDriverWait(driver, 0.1).until(EC.all_of( | ||
EC.title_is("Hello WebDriver"), | ||
EC.visibility_of_element_located((By.ID, "oneline")))) | ||
assert results[0] is True | ||
assert type(results[1]) is WebElement | ||
|
||
|
||
def test_all_of_false(driver, pages): | ||
pages.load("simpleTest.html") | ||
with pytest.raises(TimeoutException): | ||
WebDriverWait(driver, 0.1).until(EC.all_of( | ||
EC.title_is("Nope"), EC.title_is("Still Nope"))) | ||
|
||
|
||
def test_none_of_true(driver, pages): | ||
pages.load("simpleTest.html") | ||
WebDriverWait(driver, 0.1).until(EC.none_of( | ||
EC.title_is("Nope"), EC.title_is("Still Nope"))) | ||
|
||
|
||
def test_none_of_false(driver, pages): | ||
pages.load("simpleTest.html") | ||
with pytest.raises(TimeoutException): | ||
WebDriverWait(driver, 0.1).until(EC.none_of( | ||
EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) |