Path: blob/trunk/py/test/selenium/webdriver/support/expected_conditions_tests.py
1865 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import pytest1819from selenium.common.exceptions import TimeoutException20from selenium.webdriver.common.by import By21from selenium.webdriver.remote.webelement import WebElement22from selenium.webdriver.support import expected_conditions as EC23from selenium.webdriver.support.wait import WebDriverWait242526def test_any_of_true(driver, pages):27pages.load("simpleTest.html")28WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver")))293031def test_any_of_false(driver, pages):32pages.load("simpleTest.html")33with pytest.raises(TimeoutException):34WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Still Nope")))353637def test_all_of_true(driver, pages):38pages.load("simpleTest.html")39results = WebDriverWait(driver, 0.1).until(40EC.all_of(EC.title_is("Hello WebDriver"), EC.visibility_of_element_located((By.ID, "oneline")))41)42assert results[0] is True43assert isinstance(results[1], WebElement)444546def test_all_of_false(driver, pages):47pages.load("simpleTest.html")48with pytest.raises(TimeoutException):49WebDriverWait(driver, 0.1).until(EC.all_of(EC.title_is("Nope"), EC.title_is("Still Nope")))505152def test_none_of_true(driver, pages):53pages.load("simpleTest.html")54WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Still Nope")))555657def test_none_of_false(driver, pages):58pages.load("simpleTest.html")59with pytest.raises(TimeoutException):60WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver")))616263def test_clickable_locator_true(driver, pages):64pages.load("simpleTest.html")65WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "multilinelink")))666768def test_clickable_locator_false(driver, pages):69pages.load("simpleTest.html")70with pytest.raises(TimeoutException):71# text element, should not be clickable72WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "hiddenline")))737475def test_clickable_element_true(driver, pages):76pages.load("simpleTest.html")77target = (By.ID, "multilinelink")78element = driver.find_element(*target) # grab element at locator79WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable(element))808182def test_clickable_element_false(driver, pages):83pages.load("simpleTest.html")84with pytest.raises(TimeoutException):85target = (By.ID, "hiddenline") # text, should not be clickable86element = driver.find_element(*target) # grab element at locator87WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable(element))888990