Path: blob/trunk/py/test/selenium/webdriver/common/implicit_waits_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 NoSuchElementException20from selenium.webdriver.common.by import By212223def test_should_implicitly_wait_for_asingle_element(driver, pages):24pages.load("dynamic.html")25add = driver.find_element(By.ID, "adder")26driver.implicitly_wait(3)27add.click()28driver.find_element(By.ID, "box0") # All is well if this doesn't throw.293031def test_should_still_fail_to_find_an_element_when_implicit_waits_are_enabled(driver, pages):32pages.load("dynamic.html")33driver.implicitly_wait(0.5)34with pytest.raises(NoSuchElementException):35driver.find_element(By.ID, "box0")363738def test_should_return_after_first_attempt_to_find_one_after_disabling_implicit_waits(driver, pages):39pages.load("dynamic.html")40driver.implicitly_wait(3)41driver.implicitly_wait(0)42with pytest.raises(NoSuchElementException):43driver.find_element(By.ID, "box0")444546def test_should_implicitly_wait_until_at_least_one_element_is_found_when_searching_for_many(driver, pages):47pages.load("dynamic.html")48add = driver.find_element(By.ID, "adder")4950driver.implicitly_wait(2)51add.click()52add.click()5354elements = driver.find_elements(By.CLASS_NAME, "redbox")55assert len(elements) >= 1565758def test_should_still_fail_to_find_an_elemenst_when_implicit_waits_are_enabled(driver, pages):59pages.load("dynamic.html")6061driver.implicitly_wait(0.5)62elements = driver.find_elements(By.CLASS_NAME, "redbox")63assert 0 == len(elements)646566def test_should_return_after_first_attempt_to_find_many_after_disabling_implicit_waits(driver, pages):67pages.load("dynamic.html")68add = driver.find_element(By.ID, "adder")69driver.implicitly_wait(1.1)70driver.implicitly_wait(0)71add.click()72elements = driver.find_elements(By.CLASS_NAME, "redbox")73assert 0 == len(elements)747576