Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/implicit_waits_tests.py
1865 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
import pytest
19
20
from selenium.common.exceptions import NoSuchElementException
21
from selenium.webdriver.common.by import By
22
23
24
def test_should_implicitly_wait_for_asingle_element(driver, pages):
25
pages.load("dynamic.html")
26
add = driver.find_element(By.ID, "adder")
27
driver.implicitly_wait(3)
28
add.click()
29
driver.find_element(By.ID, "box0") # All is well if this doesn't throw.
30
31
32
def test_should_still_fail_to_find_an_element_when_implicit_waits_are_enabled(driver, pages):
33
pages.load("dynamic.html")
34
driver.implicitly_wait(0.5)
35
with pytest.raises(NoSuchElementException):
36
driver.find_element(By.ID, "box0")
37
38
39
def test_should_return_after_first_attempt_to_find_one_after_disabling_implicit_waits(driver, pages):
40
pages.load("dynamic.html")
41
driver.implicitly_wait(3)
42
driver.implicitly_wait(0)
43
with pytest.raises(NoSuchElementException):
44
driver.find_element(By.ID, "box0")
45
46
47
def test_should_implicitly_wait_until_at_least_one_element_is_found_when_searching_for_many(driver, pages):
48
pages.load("dynamic.html")
49
add = driver.find_element(By.ID, "adder")
50
51
driver.implicitly_wait(2)
52
add.click()
53
add.click()
54
55
elements = driver.find_elements(By.CLASS_NAME, "redbox")
56
assert len(elements) >= 1
57
58
59
def test_should_still_fail_to_find_an_elemenst_when_implicit_waits_are_enabled(driver, pages):
60
pages.load("dynamic.html")
61
62
driver.implicitly_wait(0.5)
63
elements = driver.find_elements(By.CLASS_NAME, "redbox")
64
assert 0 == len(elements)
65
66
67
def test_should_return_after_first_attempt_to_find_many_after_disabling_implicit_waits(driver, pages):
68
pages.load("dynamic.html")
69
add = driver.find_element(By.ID, "adder")
70
driver.implicitly_wait(1.1)
71
driver.implicitly_wait(0)
72
add.click()
73
elements = driver.find_elements(By.CLASS_NAME, "redbox")
74
assert 0 == len(elements)
75
76