Skip to content

Commit

Permalink
gui_e2e: make email notifications test more robust
Browse files Browse the repository at this point in the history
Instead of asserting that the count is zero or not zero, let's take into
account the current stats before running the test. Now we are asserting
that the total notifications sent count has changed and the total
failures has remained the same.

This makes the test more robust because now notification failures from
other tests don't have an influence on what we are asserting in this
test.

CMK-21533

Change-Id: I79728f2929d83421518fadd4b4280f312e442367
  • Loading branch information
logan-connolly committed Feb 13, 2025
1 parent 0805142 commit 14345f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions tests/gui_e2e/test_email_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_filesystem_email_notifications(

logger.info("Clone the existing default notification rule")
notification_configuration_page = NotificationConfiguration(dashboard_page.page)
total_sent = notification_configuration_page.get_total_sent_notifications_count()
total_failures = notification_configuration_page.get_failed_notifications_count()
logger.info("Current notification stats: sent=%s, failed=%s", total_sent, total_failures)
# The scrollbar interrupts the interaction with rule edit button -> collapse overview
notification_configuration_page.collapse_notification_overview(True)
notification_configuration_page.notification_rule_copy_button(0).click()
Expand Down Expand Up @@ -112,8 +115,8 @@ def test_filesystem_email_notifications(
notification_configuration_page.navigate()
# The notifications stats need to be read -> open overview
notification_configuration_page.collapse_notification_overview(False)
notification_configuration_page.check_total_sent_notifications_is_not_zero()
notification_configuration_page.check_failed_notifications_is_zero()
notification_configuration_page.check_total_sent_notifications_has_changed(total_sent)
notification_configuration_page.check_failed_notifications_has_not_changed(total_failures)

with manage_new_page_from_browser_context(service_search_page.page.context) as new_page:
email_page = EmailPage(new_page, html_file_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ def _get_notification_stat_count(self, title: str) -> Locator:
.get_by_role("paragraph")
)

def check_total_sent_notifications_is_not_zero(self) -> None:
def get_total_sent_notifications_count(self) -> int:
return int(self._get_notification_stat_count("Total sent notifications").inner_text())

def check_total_sent_notifications_has_changed(self, previous_count: int) -> None:
locator = self._get_notification_stat_count("Total sent notifications")
expect(locator).not_to_have_text(re.compile(r"^0$")) # "0" isn't valid
expect(locator).not_to_have_text(re.compile(rf"^{previous_count}$"))

def get_failed_notifications_count(self) -> int:
return int(self._get_notification_stat_count("Failed notifications").inner_text())

def check_failed_notifications_is_zero(self) -> None:
def check_failed_notifications_has_not_changed(self, previous_count: int) -> None:
locator = self._get_notification_stat_count("Failed notifications")
expect(locator).to_have_text(re.compile(r"^\s0$")) # " 0" is valid
expect(locator).to_have_text(re.compile(rf"^\s{previous_count}$"))

0 comments on commit 14345f5

Please sign in to comment.