Skip to content

Commit 93b513d

Browse files
authored
Merge pull request #2823 from TillerBurr/wait-for-none
Fix: `None` in "wait" Methods Causing Incorrectly Passing Tests
2 parents 93195fa + 36fde21 commit 93b513d

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

dash/testing/wait.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=too-few-public-methods
22
"""Utils methods for pytest-dash such wait_for wrappers."""
3+
34
import time
45
import logging
56
from selenium.common.exceptions import WebDriverException
@@ -62,8 +63,9 @@ def __call__(self, driver):
6263
try:
6364
elem = driver.find_element(By.CSS_SELECTOR, self.selector)
6465
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")
66+
value = elem.get_attribute("value")
67+
return self.text in str(elem.text) or (
68+
value is not None and self.text in str(value)
6769
)
6870
except WebDriverException:
6971
return False
@@ -107,9 +109,9 @@ def __call__(self, driver):
107109
try:
108110
elem = self._get_element(driver)
109111
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
112+
value = elem.get_attribute("value")
113+
return str(elem.text) == self.text or (
114+
value is not None and str(value) == self.text
113115
)
114116
except WebDriverException:
115117
return False

tests/integration/test_duo.py

Lines changed: 28 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,10 +32,33 @@ 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

3346
assert (
3447
err.value.args[0]
3548
== "text -> none not found inside element within 1.0s, #none not found"
3649
)
50+
51+
52+
def test_duo002_wait_for_text_value(dash_duo):
53+
app = Dash(__name__)
54+
app.layout = html.Div([html.Ol([html.Li("Item", id="value-item", value="100")])])
55+
dash_duo.start_server(app)
56+
57+
dash_duo.wait_for_text_to_equal("#value-item", "100")
58+
with pytest.raises(TimeoutException) as err:
59+
dash_duo.wait_for_contains_text("#value-item", "None", timeout=1.0)
60+
61+
assert (
62+
err.value.args[0]
63+
== "text -> None not found inside element within 1.0s, found: Item"
64+
)

0 commit comments

Comments
 (0)