Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 5, 2020

Conversation

tpapaioa
Copy link
Contributor

@tpapaioa tpapaioa commented Mar 5, 2020

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"]')

@mshriver mshriver self-assigned this Mar 5, 2020
@mshriver mshriver added the bug label Mar 5, 2020
@coveralls
Copy link

coveralls commented Mar 5, 2020

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@tpapaioa tpapaioa changed the title [WIPTEST] Add NoSuchElementException handling back into FlashMessages. [RFR] Add NoSuchElementException handling back into FlashMessages. Mar 5, 2020
@mshriver mshriver merged commit 4b32fa7 into RedHatQE:master Mar 5, 2020
@tpapaioa tpapaioa deleted the flashmessages_msg_count_fix branch March 5, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants