Skip to content

Commit 234c999

Browse files
carlosrohlmtierney
authored andcommitted
Add expected conditions based on URL to Python Expected Conditions (#4160)
1 parent 860b3f7 commit 234c999

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

py/selenium/webdriver/support/expected_conditions.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,55 @@ def __call__(self, driver):
6363
return _find_element(driver, self.locator)
6464

6565

66+
class url_contains(object):
67+
""" An expectation for checking that the current url contains a
68+
case-sensitive substring.
69+
url is the fragment of url expected,
70+
returns True when the title matches, False otherwise
71+
"""
72+
def __init__(self, url):
73+
self.url = url
74+
75+
def __call__(self, driver):
76+
return self.url in driver.current_url
77+
78+
79+
class url_matches(object):
80+
"""An expectation for checking the current url.
81+
pattern is the expected pattern, which must be an exact match
82+
returns True if the title matches, false otherwise."""
83+
def __init__(self, pattern):
84+
self.pattern = pattern
85+
86+
def __call__(self, driver):
87+
import re
88+
match = re.search(self.pattern, driver.current_url)
89+
90+
return match != None
91+
92+
93+
class url_to_be(object):
94+
"""An expectation for checking the current url.
95+
url is the expected url, which must be an exact match
96+
returns True if the title matches, false otherwise."""
97+
def __init__(self, url):
98+
self.url = url
99+
100+
def __call__(self, driver):
101+
return self.url == driver.current_url
102+
103+
104+
class url_changes(object):
105+
"""An expectation for checking the current url.
106+
url is the expected url, which must not be an exact match
107+
returns True if the url is different, false otherwise."""
108+
def __init__(self, url):
109+
self.url = url
110+
111+
def __call__(self, driver):
112+
return self.url != driver.current_url
113+
114+
66115
class visibility_of_element_located(object):
67116
""" An expectation for checking that an element is present on the DOM of a
68117
page and visible. Visibility means that the element is not only displayed

0 commit comments

Comments
 (0)