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

Code before:
        wait_cond,
        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)
            if (value := elem.get_attribute("value")) is not None:
                return self.text in str(elem.text) or self.text in str(value)
            return self.text in str(elem.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):
@TillerBurr Can you change the logic here as well to remove the walrus operator? Once that's done, this PR looks good to me.

Code after:
        wait_cond,
        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: