Skip to content

Commit 98e3a80

Browse files
committed
Fix "None" in wait causing incorrect tests
1 parent 230d664 commit 98e3a80

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

dash/testing/wait.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def __call__(self, driver):
6262
try:
6363
elem = driver.find_element(By.CSS_SELECTOR, self.selector)
6464
logger.debug("contains text {%s} => expected %s", elem.text, self.text)
65-
return self.text in str(elem.text) or self.text in str(
66-
elem.get_attribute("value")
67-
)
65+
if value := elem.get_attribute("value") is not None:
66+
return self.text in str(elem.text) or self.text in str(value)
67+
else:
68+
return self.text in str(elem.text)
6869
except WebDriverException:
6970
return False
7071

@@ -107,10 +108,10 @@ def __call__(self, driver):
107108
try:
108109
elem = self._get_element(driver)
109110
logger.debug("text to equal {%s} => expected %s", elem.text, self.text)
110-
return (
111-
str(elem.text) == self.text
112-
or str(elem.get_attribute("value")) == self.text
113-
)
111+
if value := elem.get_attribute("value") is not None:
112+
return str(elem.text) == self.text or str(value) == self.text
113+
else:
114+
return str(elem.text) == self.text
114115
except WebDriverException:
115116
return False
116117

tests/integration/test_duo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ def test_duo001_wait_for_text_error(dash_duo):
1414

1515
assert err.value.args[0] == "text -> Invalid not found within 1.0s, found: Content"
1616

17+
with pytest.raises(TimeoutException) as err:
18+
dash_duo.wait_for_text_to_equal("#content", "None", timeout=1.0)
19+
20+
assert err.value.args[0] == "text -> None not found within 1.0s, found: Content"
21+
1722
with pytest.raises(TimeoutException) as err:
1823
dash_duo.wait_for_text_to_equal("#none", "None", timeout=1.0)
1924

@@ -27,6 +32,14 @@ def test_duo001_wait_for_text_error(dash_duo):
2732
== "text -> invalid not found inside element within 1.0s, found: Content"
2833
)
2934

35+
with pytest.raises(TimeoutException) as err:
36+
dash_duo.wait_for_contains_text("#content", "None", timeout=1.0)
37+
38+
assert (
39+
err.value.args[0]
40+
== "text -> None not found inside element within 1.0s, found: Content"
41+
)
42+
3043
with pytest.raises(TimeoutException) as err:
3144
dash_duo.wait_for_contains_text("#none", "none", timeout=1.0)
3245

0 commit comments

Comments
 (0)