RedHatQE / widgetastic.patternfly

Library of Patternfly widgets for Widgetastic.
Other
13 stars 29 forks source link

[RFR] Add NoSuchElementException handling back into FlashMessages. #118

Closed tpapaioa closed 4 years ago

tpapaioa commented 4 years ago

In the older Widget-based implementation of FlashMessages, there was silent catching of NoSuchElementException if there was no flash message block found on the page:

    @property
    def messages(self):
        result = []
        msg_xpath = ('.//div[@id="flash_text_div" or '
                     'contains(@class, "flash_text_div")]/div[contains(@class, "alert")]')
        try:

            for flash_div in self.browser.elements(msg_xpath, parent=self, check_visibility=True):
                result.append(FlashMessage(self, flash_div, logger=self.logger))
        except NoSuchElementException:
            pass
        return result

The newer View-based implementation refactored the message lookup to use a generator, and ended up dropping this exception handling. This PR restores it, in the msg_count property that gets called by the generator to look up the number of flash messages present. Now, if a view contains a nested FlashMessages view that does not actually get displayed, calls to methods like view.flash.assert_no_error() will succeed instead of erroring out like this:

E           selenium.common.exceptions.NoSuchElementException: Message: Could not find an element Locator(by='xpath', locator='.//div[@id="flash_msg_div"]')
coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.02%) to 52.906% when pulling 6274acf1ba2a5f289115cbe6b1bd48bb18629ffd on tpapaioa:flashmessages_msg_count_fix into 973098174f6294c28be40eff65ab16c7d1f339d6 on RedHatQE:master.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.04%) to 52.839% when pulling 6274acf1ba2a5f289115cbe6b1bd48bb18629ffd on tpapaioa:flashmessages_msg_count_fix into 973098174f6294c28be40eff65ab16c7d1f339d6 on RedHatQE:master.