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

Code before:

    def __call__(self, driver):
        try:
            elem = driver.find_element(By.CSS_SELECTOR, self.selector)
            classname = elem.get_attribute("class")
            logger.debug(
                "contains class {%s} => expected %s", classname, self.classname
            )
            return self.classname in str(classname).split(" ")
        except WebDriverException:
            return False


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

    def __call__(self, driver):
        try:
            elem = self._get_element(driver)
            logger.debug("text to equal {%s} => expected %s", elem.text, self.text)
            if (value := elem.get_attribute("value")) is not None:
                return str(elem.text) == self.text or str(value) == self.text
            return str(elem.text) == 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 within {self.timeout}s, {text}"

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


class style_to_equal:
    def __init__(self, selector, style, val):
        self.selector = selector
        self.style = style
        self.val = val

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

Review comment (suggestion):
```suggestion
            value = elem.get_attribute("value")
            return str(elem.text) == self.text or (value is not None and str(value) == self.text)
```

IMO better to avoid the walrus operator here as it's clearer without. Same goes for the other function.

Code after:
        self.selector = selector
        self.classname = classname

    def __call__(self, driver):
        try:
            elem = driver.find_element(By.CSS_SELECTOR, self.selector)
            classname = elem.get_attribute("class")
            logger.debug(
                "contains class {%s} => expected %s", classname, self.classname
            )
            return self.classname in str(classname).split(" ")
        except WebDriverException:
            return False


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

    def __call__(self, driver):
        try:
            elem = self._get_element(driver)
            logger.debug("text to equal {%s} => expected %s", elem.text, 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

    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 within {self.timeout}s, {text}"

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


class style_to_equal:
    def __init__(self, selector, style, val):
        self.selector = selector
        self.style = style
        self.val = val

    def __call__(self, driver):