Skip to content

Commit d3d7360

Browse files
author
Lachlan Teale
committed
Added wait_for_contains_class
1 parent 16f81f4 commit d3d7360

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

dash/testing/browser.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
style_to_equal,
2727
class_to_equal,
2828
contains_text,
29+
contains_class,
2930
until,
3031
)
3132
from dash.testing.dash_page import DashPageMixin
@@ -343,6 +344,20 @@ def wait_for_text_to_equal(self, selector, text, timeout=None):
343344
msg=f"text -> {text} not found within {timeout or self._wait_timeout}s",
344345
)
345346

347+
def wait_for_contains_class(self, selector, classname, timeout=None):
348+
"""Explicit wait until the element's classes contains the expected `classname`.
349+
350+
timeout if not set, equals to the fixture's `wait_timeout`
351+
shortcut to `WebDriverWait` with customized `contains_class`
352+
condition.
353+
"""
354+
return self._wait_for(
355+
method=contains_class,
356+
args=(selector, classname),
357+
timeout=timeout,
358+
msg=f"classname -> {classname} not found inside element within {timeout or self._wait_timeout}s",
359+
)
360+
346361
def wait_for_contains_text(self, selector, text, timeout=None):
347362
"""Explicit wait until the element's text contains the expected `text`.
348363

dash/testing/wait.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ def __call__(self, driver):
6868
return False
6969

7070

71+
class contains_class:
72+
def __init__(self, selector, classname):
73+
self.selector = selector
74+
self.classname = classname
75+
76+
def __call__(self, driver):
77+
try:
78+
elem = driver.find_element(By.CSS_SELECTOR, self.selector)
79+
classname = elem.get_attribute("class")
80+
logger.debug(
81+
"contains class {%s} => expected %s", classname, self.classname
82+
)
83+
return self.classname in str(classname)
84+
except WebDriverException:
85+
return False
86+
87+
7188
class text_to_equal:
7289
def __init__(self, selector, text):
7390
self.selector = selector

0 commit comments

Comments
 (0)