Skip to content

Commit

Permalink
Merge pull request mozilla#6277 from emilghittasv/playwright-add-mess…
Browse files Browse the repository at this point in the history
…aging-system-notification-coverage

Playwright expand test coverage over the unread new message UI notification
  • Loading branch information
emilghittasv authored Oct 7, 2024
2 parents e08d26f + 5b8fefb commit 1219f6a
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 3 deletions.
13 changes: 13 additions & 0 deletions playwright_tests/pages/messaging_system_pages/inbox_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class InboxPage(BasePage):
__inbox_messages_section = "//ol[@class='inbox-table']"
__inbox_messages_delete_button = "//div[@class='email-cell delete']//a[@class='delete']"
__inbox_delete_checkbox = "//div[@class='email-cell check']/input"
__all_unread_messages = "//li[@class='email-row unread']"
__all_read_messages_excerpt = ("//ol[@class='inbox-table']//li[not(contains(@class,'unread'))]"
"/div[@class='email-cell excerpt']/a")

def __init__(self, page: Page):
super().__init__(page)
Expand Down Expand Up @@ -125,6 +128,9 @@ def _inbox_message_element_handles(self, excerpt: str) -> list[ElementHandle]:
def are_inbox_messages_displayed(self) -> bool:
return self._is_element_visible(self.__inbox_messages_section)

def get_all_read_messages_excerpt(self) -> list[str]:
return self._get_text_of_elements(self.__all_read_messages_excerpt)

def delete_all_inbox_messages(self):
inbox_messages_count = self._get_element_handles(self.__inbox_messages)
for i in range(len(inbox_messages_count)):
Expand All @@ -135,6 +141,10 @@ def delete_all_inbox_messages(self):
delete_button.click()
self.click_on_delete_page_delete_button()

def check_a_particular_message(self, excerpt=''):
inbox_checkbox = self.inbox_message_select_checkbox_element(excerpt)
inbox_checkbox[0].click()

def delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):
if excerpt != '':
inbox_messages_count = self._inbox_message_element_handles(excerpt)
Expand All @@ -152,3 +162,6 @@ def delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):

self.click_on_inbox_delete_selected_button()
self.click_on_delete_page_delete_button()

def get_all_unread_messages(self) -> list[Locator]:
return self._get_elements_locators(self.__all_unread_messages)
15 changes: 15 additions & 0 deletions playwright_tests/pages/top_navbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class TopNavbar(BasePage):
__signed_in_settings_option = "//h4[contains(text(), 'Settings')]/parent::a"
__signed_in_inbox_option = "//h4[contains(text(), 'Inbox')]/parent::a"
__sign_out_button = "//a[contains(text(), 'Sign Out')]"
__unread_message_profile_notification = ("//div[@id='profile-navigation']//"
"div[@class='avatar-container-message-alert']")
__unread_message_count = "//span[@class='message-count-alert']"

def __init__(self, page: Page):
super().__init__(page)
Expand Down Expand Up @@ -258,6 +261,18 @@ def click_on_my_questions_profile_option(self):
def get_text_of_logged_in_username(self) -> str:
return self._get_text_of_element(self.__signed_in_username)

def is_unread_message_notification_displayed(self) -> bool:
return self._is_element_visible(self.__unread_message_profile_notification)

def get_unread_message_notification_counter_value(self) -> int:
return int(self._get_text_of_element(self.__unread_message_count))

def is_unread_message_notification_counter_visible(self) -> bool:
return self._is_element_visible(self.__unread_message_count)

def mouse_over_profile_avatar(self):
self._hover_over_element(self.__signed_in_username)

"""
General actions against the top-navbar section.
"""
Expand Down
135 changes: 132 additions & 3 deletions playwright_tests/tests/messaging_system_tests/test_messaging_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_there_are_no_messages_here_text_is_displayed_when_no_messages_are_avail
) == SentMessagesPageMessages.NO_MESSAGES_IN_SENT_MESSAGES_TEXT


# T5697913
# T5697913, C2706735
# This test needs to be updated to fetch the username from a different place
@pytest.mark.messagingSystem
def test_private_messages_can_be_sent_via_user_profiles(page: Page, is_firefox):
Expand Down Expand Up @@ -114,12 +114,23 @@ def test_private_messages_can_be_sent_via_user_profiles(page: Page, is_firefox):
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_2"]
))

with allure.step("Verifying that the recipient user is visually notified about having a new "
"unread message"):
assert sumo_pages.top_navbar.is_unread_message_notification_displayed()

with allure.step("Accessing the Inbox section"):
sumo_pages.top_navbar.click_on_inbox_option()

with allure.step("Verifying that the inbox contains the previously sent messages"):
expect(sumo_pages.inbox_page._inbox_message_based_on_excerpt(message_body)).to_be_visible()

with allure.step("Fetching the unread messages count and verifying that the counter displays "
"the correct data"):
unread_messages = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
assert (unread_messages == sumo_pages.top_navbar.
get_unread_message_notification_counter_value())

with allure.step("Deleting the messages from the inbox section"):
sumo_pages.messaging_system_flow.delete_message_flow(
excerpt=message_body, from_inbox_list=True)
Expand All @@ -132,6 +143,12 @@ def test_private_messages_can_be_sent_via_user_profiles(page: Page, is_firefox):
assert sumo_pages.sent_message_page.get_sent_messages_page_deleted_banner_text(
) == SentMessagesPageMessages.DELETE_MESSAGE_BANNER_TEXT

with allure.step("Verifying that the notification and the unread messages counter is no "
"longer displayed near the user avatar"):
assert not sumo_pages.top_navbar.is_unread_message_notification_displayed()
sumo_pages.top_navbar.mouse_over_profile_avatar()
assert not sumo_pages.top_navbar.is_unread_message_notification_counter_visible()


# C891419
@pytest.mark.messagingSystem
Expand Down Expand Up @@ -417,6 +434,117 @@ def test_new_message_cancel_button(page: Page):
expect(sumo_pages.inbox_page._inbox_message_based_on_excerpt(message_body)).to_be_hidden()


# C2706741, C2706736, C2706740, C2706739, C2706735
@pytest.mark.messagingSystem
def test_messaging_system_unread_notification_after_message_deletion(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
content_first_message = "Test Test " + utilities.generate_random_number(1,100)
content_second_message = "Test Test " + utilities.generate_random_number(1, 100)

test_user = utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_13"]
)

with allure.step("Signing in with a non-admin user account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))

with allure.step("Accessing the inbox section and navigating to the new message page"):
sumo_pages.top_navbar.click_on_inbox_option()
sumo_pages.mess_system_user_navbar.click_on_messaging_system_nav_new_message()

with allure.step("Sending the first message"):
sumo_pages.messaging_system_flow.complete_send_message_form_with_data(
recipient_username=test_user,
message_body=content_first_message,
)

sumo_pages.mess_system_user_navbar.click_on_messaging_system_nav_new_message()
with allure.step("Sending the second message"):
sumo_pages.messaging_system_flow.complete_send_message_form_with_data(
recipient_username=test_user,
message_body=content_second_message,
)

with allure.step("Deleting sent messages"):
sumo_pages.sent_message_page.delete_all_sent_messages_via_delete_selected_button()

with allure.step("Signing in with the recipient"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_13"]
))

with allure.step("Navigating to the inbox section"):
sumo_pages.top_navbar.click_on_inbox_option()

with allure.step("Verifying that the avatar notification and the new message counter is "
"correct"):
inbox_messages_count = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
assert (sumo_pages.top_navbar
.get_unread_message_notification_counter_value() == inbox_messages_count)
assert sumo_pages.top_navbar.is_unread_message_notification_displayed()

with allure.step("Marking the first received message as read"):
sumo_pages.inbox_page.check_a_particular_message(content_first_message)
sumo_pages.inbox_page.click_on_inbox_mark_selected_as_read_button()

with allure.step("Verifying that the message is successfully marked as read"):
assert content_first_message in sumo_pages.inbox_page.get_all_read_messages_excerpt()

with allure.step("Verifying that the new message notification counter resembles the unread "
"inbox message count"):
inbox_messages_count = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
assert (sumo_pages.top_navbar
.get_unread_message_notification_counter_value() == inbox_messages_count)
assert sumo_pages.top_navbar.is_unread_message_notification_displayed()

with allure.step("Deleting the first message"):
sumo_pages.messaging_system_flow.delete_message_flow(
excerpt=content_first_message, from_inbox_list=True)

with allure.step("Verifying that the new message notification counter resembles the unread "
"inbox message count"):
inbox_messages_count = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
assert (sumo_pages.top_navbar
.get_unread_message_notification_counter_value() == inbox_messages_count)
assert sumo_pages.top_navbar.is_unread_message_notification_displayed()

with allure.step("Marking the second received message as read"):
sumo_pages.inbox_page.check_a_particular_message(content_second_message)
sumo_pages.inbox_page.click_on_inbox_mark_selected_as_read_button()

with allure.step("Verifying that the new message notification counter resembles the unread "
"inbox message count"):
inbox_messages_count = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
if inbox_messages_count == 0:
assert not sumo_pages.top_navbar.is_unread_message_notification_counter_visible()
assert not sumo_pages.top_navbar.is_unread_message_notification_displayed()
else:
assert (sumo_pages.top_navbar
.get_unread_message_notification_counter_value() == inbox_messages_count)
assert sumo_pages.top_navbar.is_unread_message_notification_displayed()

with allure.step("Deleting the second received message"):
sumo_pages.messaging_system_flow.delete_message_flow(
excerpt=content_second_message, from_inbox_list=True)

with allure.step("Verifying that the new message notification counter resembles the unread "
"inbox message count"):
inbox_messages_count = len(sumo_pages.inbox_page.get_all_unread_messages())
sumo_pages.top_navbar.mouse_over_profile_avatar()
if inbox_messages_count == 0:
assert not sumo_pages.top_navbar.is_unread_message_notification_counter_visible()
else:
assert (sumo_pages.top_navbar
.get_unread_message_notification_counter_value() == inbox_messages_count)


# C891418
@pytest.mark.messagingSystem
def test_new_message_preview(page: Page):
Expand All @@ -428,7 +556,7 @@ def test_new_message_preview(page: Page):

with allure.step("Signing in with a non-admin user account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_4"]
))

username = sumo_pages.top_navbar.get_text_of_logged_in_username()
Expand Down Expand Up @@ -507,7 +635,8 @@ def test_new_message_preview(page: Page):
utilities.user_secrets_accounts["TEST_ACCOUNT_13"]
))
sumo_pages.top_navbar.click_on_inbox_option()
expect(sumo_pages.inbox_page.inbox_message(username=username)).to_be_hidden()
expect(sumo_pages.inbox_page.inbox_message(username=username)
).to_be_hidden()


# C891421, C891424
Expand Down

0 comments on commit 1219f6a

Please sign in to comment.