Skip to content

Fix: None in "wait" Methods Causing Incorrectly Passing Tests #2823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 19, 2024
12 changes: 7 additions & 5 deletions dash/testing/wait.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=too-few-public-methods
"""Utils methods for pytest-dash such wait_for wrappers."""

import time
import logging
from selenium.common.exceptions import WebDriverException
Expand Down Expand Up @@ -62,8 +63,9 @@ def __call__(self, driver):
try:
elem = driver.find_element(By.CSS_SELECTOR, self.selector)
logger.debug("contains text {%s} => expected %s", elem.text, self.text)
return self.text in str(elem.text) or self.text in str(
elem.get_attribute("value")
value = elem.get_attribute("value")
return self.text in str(elem.text) or (
value is not None and self.text in str(value)
)
except WebDriverException:
return False
Expand Down Expand Up @@ -107,9 +109,9 @@ def __call__(self, driver):
try:
elem = self._get_element(driver)
logger.debug("text to equal {%s} => expected %s", elem.text, self.text)
return (
str(elem.text) == self.text
or str(elem.get_attribute("value")) == self.text
value = elem.get_attribute("value")
return str(elem.text) == self.text or (
value is not None and str(value) == self.text
)
except WebDriverException:
return False
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/test_duo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def test_duo001_wait_for_text_error(dash_duo):

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

with pytest.raises(TimeoutException) as err:
dash_duo.wait_for_text_to_equal("#content", "None", timeout=1.0)

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

with pytest.raises(TimeoutException) as err:
dash_duo.wait_for_text_to_equal("#none", "None", timeout=1.0)

Expand All @@ -27,10 +32,33 @@ def test_duo001_wait_for_text_error(dash_duo):
== "text -> invalid not found inside element within 1.0s, found: Content"
)

with pytest.raises(TimeoutException) as err:
dash_duo.wait_for_contains_text("#content", "None", timeout=1.0)

assert (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

err.value.args[0]
== "text -> None not found inside element within 1.0s, found: Content"
)

with pytest.raises(TimeoutException) as err:
dash_duo.wait_for_contains_text("#none", "none", timeout=1.0)

assert (
err.value.args[0]
== "text -> none not found inside element within 1.0s, #none not found"
)


def test_duo002_wait_for_text_value(dash_duo):
app = Dash(__name__)
app.layout = html.Div([html.Ol([html.Li("Item", id="value-item", value="100")])])
dash_duo.start_server(app)

dash_duo.wait_for_text_to_equal("#value-item", "100")
with pytest.raises(TimeoutException) as err:
dash_duo.wait_for_contains_text("#value-item", "None", timeout=1.0)

assert (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

err.value.args[0]
== "text -> None not found inside element within 1.0s, found: Item"
)