Repository: plotly/dash
File: dash/testing/wait.py (Python)

Code before:
        timeout,
        poll,
    )
    end_time = time.time() + timeout
    while res:
        if time.time() > end_time:
            raise TestingTimeoutError(msg)
        time.sleep(poll)
        res = wait_cond()
        logger.debug("poll => %s", time.time())

    return res


class contains_text:
    def __init__(self, selector, text, timeout):
        self.selector = selector
        self.text = text
        self.timeout = timeout

    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)
            value = elem.get_attribute("value")
            return str(elem.text) in self.text or (
                value is not None and str(value) in self.text
            )
        except WebDriverException:
            return False

    def message(self, driver):
        try:
            element = self._get_element(driver)
            text = "found: " + str(element.text) or str(element.get_attribute("value"))
        except WebDriverException:
            text = f"{self.selector} not found"
        return f"text -> {self.text} not found inside element within {self.timeout}s, {text}"

    def _get_element(self, driver):
        return driver.find_element(By.CSS_SELECTOR, self.selector)


class contains_class:
    def __init__(self, selector, classname):
        self.selector = selector
        self.classname = classname

    def __call__(self, driver):
        try:
            elem = driver.find_element(By.CSS_SELECTOR, self.selector)

Review comment (suggestion):
This is swapped -- should be `self.text in str(elem.text)` and `self.text in str(value)`

Code after:
        timeout,
        poll,
    )
    end_time = time.time() + timeout
    while res:
        if time.time() > end_time:
            raise TestingTimeoutError(msg)
        time.sleep(poll)
        res = wait_cond()
        logger.debug("poll => %s", time.time())

    return res


class contains_text:
    def __init__(self, selector, text, timeout):
        self.selector = selector
        self.text = text
        self.timeout = timeout

    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)
            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

    def message(self, driver):
        try:
            element = self._get_element(driver)
            text = "found: " + str(element.text) or str(element.get_attribute("value"))
        except WebDriverException:
            text = f"{self.selector} not found"
        return f"text -> {self.text} not found inside element within {self.timeout}s, {text}"

    def _get_element(self, driver):
        return driver.find_element(By.CSS_SELECTOR, self.selector)


class contains_class:
    def __init__(self, selector, classname):
        self.selector = selector
        self.classname = classname

    def __call__(self, driver):
        try:
            elem = driver.find_element(By.CSS_SELECTOR, self.selector)