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"]')
Coverage increased (+0.02%) to 52.906% when pulling 6274acf1ba2a5f289115cbe6b1bd48bb18629ffd on tpapaioa:flashmessages_msg_count_fix into 973098174f6294c28be40eff65ab16c7d1f339d6 on RedHatQE:master.
Coverage decreased (-0.04%) to 52.839% when pulling 6274acf1ba2a5f289115cbe6b1bd48bb18629ffd on tpapaioa:flashmessages_msg_count_fix into 973098174f6294c28be40eff65ab16c7d1f339d6 on RedHatQE:master.
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:
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: