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

Playwright improve and document messaging system related page objects and flows #6310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ def complete_send_message_form_with_data(self,
recipient_username='',
message_body='',
submit_message=True):
if recipient_username != '' and not isinstance(recipient_username, list):
self.new_message_page.type_into_new_message_to_input_field(recipient_username)
self.new_message_page.click_on_a_searched_user(recipient_username)
"""Complete the send message form with data.

if isinstance(recipient_username, list):
for recipient in recipient_username:
self.new_message_page.type_into_new_message_to_input_field(recipient)
self.new_message_page.click_on_a_searched_user(recipient)
Args:
recipient_username (str): The username of the recipient.
message_body (str): The body of the message.
submit_message (bool): Submit the message.
"""
if recipient_username:
if isinstance(recipient_username, list):
for recipient in recipient_username:
self.new_message_page.type_into_new_message_to_input_field(recipient)
self.new_message_page.click_on_a_searched_user(recipient)
else:
self.new_message_page.type_into_new_message_to_input_field(recipient_username)
self.new_message_page.click_on_a_searched_user(recipient_username)

if message_body != '':
if message_body:
self.new_message_page.fill_into_new_message_body_textarea(message_body)

if submit_message:
Expand All @@ -35,15 +42,26 @@ def delete_message_flow(self, username='',
delete_message=True,
from_sent_list=False,
from_inbox_list=False):
if from_sent_list and username != '':
self.sent_message_page.click_on_sent_message_delete_button_by_user(username)
elif from_sent_list and excerpt != '':
self.sent_message_page.click_on_sent_message_delete_button_by_excerpt(excerpt)

if from_inbox_list and username != '':
self.inbox_page.click_on_inbox_message_delete_button_by_username(username)
elif from_inbox_list and excerpt != '':
self.inbox_page.click_on_inbox_message_delete_button_by_excerpt(excerpt)
"""Delete a message flow.

Args:
username (str): The username of the recipient.
excerpt (str): The excerpt of the message.
delete_message (bool): Delete the message.
from_sent_list (bool): Delete the message from the sent list.
from_inbox_list (bool): Delete the message from the inbox list
"""
if from_sent_list:
if username:
self.sent_message_page.click_on_sent_message_delete_button_by_user(username)
elif excerpt:
self.sent_message_page.click_on_sent_message_delete_button_by_excerpt(excerpt)

if from_inbox_list:
if username:
self.inbox_page.click_on_inbox_message_delete_button_by_username(username)
elif excerpt:
self.inbox_page.click_on_inbox_message_delete_button_by_excerpt(excerpt)

if delete_message:
self.sent_message_page.click_on_delete_page_delete_button()
172 changes: 125 additions & 47 deletions playwright_tests/pages/messaging_system_pages/inbox_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,153 +3,230 @@


class InboxPage(BasePage):

# Breadcrumb locators.
__inbox_page_breadcrumbs = "//ol[@id='breadcrumbs']/li"
BREADCRUMB_LOCATORS = {
"inbox_page_breadcrumbs": "//ol[@id='breadcrumbs']/li"
}

# Inbox page locators.
__inbox_page_main_heading = "//h1[@class='sumo-page-heading']"
__inbox_no_messages_text = "//article[@id='inbox']//p"
__inbox_page_scam_alert_banner_text = "//div[@id='id_scam_alert']//p[@class='heading']"
__inbox_page_scam_alert_close_button = "//button[@data-close-id='id_scam_alert']"
__inbox_page_message_action_banner = "//ul[@class='user-messages']/li/p"
__inbox_page_message_action_banner_close_button = ("//button[@class='mzp-c-notification-bar"
"-button']")
INBOX_PAGE_LOCATORS = {
"inbox_page_main_heading": "//h1[@class='sumo-page-heading']",
"inbox_no_messages_text": "//article[@id='inbox']//p",
"inbox_page_scam_alert_banner_text": "//div[@id='id_scam_alert']//p[@class='heading']",
"inbox_page_scam_alert_close_button": "//button[@data-close-id='id_scam_alert']",
"inbox_page_message_action_banner": "//ul[@class='user-messages']/li/p",
"inbox_page_message_action_banner_close_button": "//button[@class='mzp-c-notification-bar-"
"button']"
}

# Inbox button locators.
__inbox_new_message_button = "//article[@id='inbox']//a[contains(text(),'New Message')]"
__inbox_mark_selected_as_read_button = "//input[@name='mark_read']"
__inbox_delete_selected_button = "//input[@name='delete']"
__inbox_delete_page_delete_button = "//button[@name='delete']"
__inbox_delete_page_cancel_button = "//a[contains(text(), 'Cancel')]"
INBOX_BUTTON_LOCATORS = {
"inbox_new_message_button": "//article[@id='inbox']//a[contains(text(),'New Message')]",
"inbox_mark_selected_as_read_button": "//input[@name='mark_read']",
"inbox_delete_selected_button": "//input[@name='delete']",
"inbox_delete_page_delete_button": "//button[@name='delete']",
"inbox_delete_page_cancel_button": "//a[contains(text(), 'Cancel')]"
}

# Inbox messages.
__inbox_messages = "//li[contains(@class,'email-row') and not(contains(@class, 'header'))]"
__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")
INBOX_MESSAGES_LOCATORS = {
"inbox_messages": "//li[contains(@class,'email-row') and not(contains(@class, 'header'))]",
"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)

# Breadcrumb actions.

# Inbox page scam alert actions.
def get_text_inbox_scam_alert_banner_text(self) -> str:
return self._get_text_of_element(self.__inbox_page_scam_alert_banner_text)
"""Get the text of the scam alert banner."""
return self._get_text_of_element(self.INBOX_PAGE_LOCATORS
["inbox_page_scam_alert_banner_text"])

def click_on_inbox_scam_alert_close_button(self):
self._click(self.__inbox_page_scam_alert_close_button)
"""Click on the close button of the scam alert banner."""
self._click(self.INBOX_PAGE_LOCATORS["inbox_page_scam_alert_close_button"])

# Inbox page actions.
def get_text_inbox_page_message_banner_text(self) -> str:
return self._get_text_of_element(self.__inbox_page_message_action_banner)
"""Get the text of the message action banner."""
return self._get_text_of_element(self.INBOX_PAGE_LOCATORS
["inbox_page_message_action_banner"])

def get_text_of_inbox_page_main_header(self) -> str:
return self._get_text_of_element(self.__inbox_page_main_heading)
"""Get the text of the main header of the inbox page."""
return self._get_text_of_element(self.INBOX_PAGE_LOCATORS["inbox_page_main_heading"])

def get_text_of_inbox_no_message_header(self) -> str:
return self._get_text_of_element(self.__inbox_no_messages_text)
"""Get the text of the no message header."""
return self._get_text_of_element(self.INBOX_PAGE_LOCATORS["inbox_no_messages_text"])

# Inbox messages actions.
def get_inbox_message_subject(self, username: str) -> str:
"""Get the subject of the inbox message.

Args:
username: The username of the message sender.
"""
return self._get_text_of_element((
f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../..//"
f"a[@class='read']"
))

# This requires a change def click_on_inbox_message_banner_close_button(self):
# self._page.locator(self.__inbox_page_message_action_banner_close_button).dispatch_event(
# type='click')

def click_on_inbox_message_delete_button_by_username(self, username: str):
"""Click on the delete button of the inbox message.

Args:
username: The username of the message sender.
"""
self._click((
f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../..//"
f"a[@class='delete']"
))

def click_on_inbox_message_delete_button_by_excerpt(self, excerpt: str):
"""Click on the delete button of the inbox message.

Args:
excerpt: The excerpt of the message.
"""
self._click(f"//div[@class='email-cell excerpt']/a[normalize-space(text())='{excerpt}']"
f"/../..//a[@class='delete']")

def click_on_inbox_new_message_button(self):
self._click(self.__inbox_new_message_button)
"""Click on the new message button."""
self._click(self.INBOX_BUTTON_LOCATORS["inbox_new_message_button"])

def click_on_inbox_mark_selected_as_read_button(self):
self._click(self.__inbox_mark_selected_as_read_button)
"""Click on the mark selected as read button."""
self._click(self.INBOX_BUTTON_LOCATORS["inbox_mark_selected_as_read_button"])

def click_on_inbox_delete_selected_button(self):
self._click(self.__inbox_delete_selected_button)
"""Click on the delete selected button."""
self._click(self.INBOX_BUTTON_LOCATORS["inbox_delete_selected_button"])

def click_on_inbox_message_sender_username(self, username: str):
"""Click on the username of the message sender.

Args:
username: The username of the message sender.
"""
self._click(f"//div[@class='email-cell from']//a[contains(text(),'{username}')]")

def inbox_message_select_checkbox_element(self, excerpt='') -> list[ElementHandle]:
"""Get the element handle of the inbox message select checkbox.

Args:
excerpt: The excerpt of the message.
"""
if excerpt != '':
return self._get_element_handles(f"//div[@class='email-cell excerpt']"
f"/a[normalize-space(text())='{excerpt}']/../.."
f"/div[@class='email-cell check']/input")
else:
return self._get_element_handles(self.__inbox_delete_checkbox)
return self._get_element_handles(self.INBOX_MESSAGES_LOCATORS["inbox_delete_checkbox"])

def click_on_inbox_message_subject(self, username: str):
"""Click on the subject of the inbox message.

Args:
username: The username of the message sender.
"""
self._click((f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../.."
f"//a[@class='read']"))

def click_on_delete_page_delete_button(self):
self._click(self.__inbox_delete_page_delete_button)
"""Click on the delete button on the delete message page."""
self._click(self.INBOX_BUTTON_LOCATORS["inbox_delete_page_delete_button"])

def click_on_delete_page_cancel_button(self):
"""Click on the cancel button on the delete message page."""
# Hitting the "Enter" button instead of click due to an issue (the banner does not close
# on click)
self._press_a_key(self.__inbox_delete_page_cancel_button, 'Enter')
self._press_a_key(self.INBOX_PAGE_LOCATORS["inbox_delete_page_cancel_button"], 'Enter')

def is_no_message_header_displayed(self) -> bool:
return self._is_element_visible(self.__inbox_no_messages_text)
"""Check if the no message header is displayed."""
return self._is_element_visible(self.INBOX_PAGE_LOCATORS["inbox_no_messages_text"])

def inbox_message_banner(self) -> Locator:
return self._get_element_locator(self.__inbox_page_scam_alert_banner_text)
"""Get the locator of the inbox message banner."""
return self._get_element_locator(self.INBOX_PAGE_LOCATORS
["inbox_page_scam_alert_banner_text"])

def inbox_message(self, username: str) -> Locator:
"""Get the locator of the inbox message.

Args:
username: The username of the message sender.
"""
return self._get_element_locator(f"//div[@class='email-cell from']//a[contains(text(),"
f"'{username}')]")

def _inbox_message_based_on_excerpt(self, excerpt: str) -> Locator:
"""Get the locator of the inbox message based on the excerpt.

Args:
excerpt: The excerpt of the message.
"""
return self._get_element_locator(f"//div[@class='email-cell excerpt']/a[normalize-space"
f"(text())='{excerpt}']")

def _inbox_message_element_handles(self, excerpt: str) -> list[ElementHandle]:
"""Get the element handles of the inbox message based on the excerpt.

Args:
excerpt: The excerpt of the message.
"""
return self._get_element_handles(f"//div[@class='email-cell excerpt']/a[normalize-space"
f"(text())='{excerpt}']")

def are_inbox_messages_displayed(self) -> bool:
return self._is_element_visible(self.__inbox_messages_section)
"""Check if the inbox messages are displayed."""
return self._is_element_visible(self.INBOX_MESSAGES_LOCATORS["inbox_messages_section"])

def get_all_read_messages_excerpt(self) -> list[str]:
return self._get_text_of_elements(self.__all_read_messages_excerpt)
"""Get the excerpt of all the read messages."""
return self._get_text_of_elements(self.INBOX_MESSAGES_LOCATORS
["all_read_messages_excerpt"])

def delete_all_inbox_messages(self):
inbox_messages_count = self._get_element_handles(self.__inbox_messages)
"""Delete all the inbox messages."""
inbox_messages_count = self._get_element_handles(self.INBOX_MESSAGES_LOCATORS
["inbox_messages"])
for i in range(len(inbox_messages_count)):
inbox_elements_delete_button = self._get_element_handles(
self.__inbox_messages_delete_button)
self.INBOX_MESSAGES_LOCATORS["inbox_messages_delete_button"])
delete_button = inbox_elements_delete_button[i]

delete_button.click()
self.click_on_delete_page_delete_button()

def check_a_particular_message(self, excerpt=''):
"""Check a particular message.

Args:
excerpt: The excerpt of the message.
"""
inbox_checkbox = self.inbox_message_select_checkbox_element(excerpt)
inbox_checkbox[0].click()
inbox_checkbox[0].check()

def delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):
"""Delete all the inbox messages via the delete selected button.

Args:
excerpt: The excerpt of the message.
"""
if excerpt != '':
inbox_messages_count = self._inbox_message_element_handles(excerpt)
else:
inbox_messages_count = self._get_element_handles(self.__inbox_messages)
inbox_messages_count = self._get_element_handles(self.INBOX_MESSAGES_LOCATORS
["inbox_messages"])
counter = 0
for i in range(len(inbox_messages_count)):
if excerpt != '':
Expand All @@ -164,4 +241,5 @@ def delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):
self.click_on_delete_page_delete_button()

def get_all_unread_messages(self) -> list[Locator]:
return self._get_elements_locators(self.__all_unread_messages)
"""Get all the unread messages."""
return self._get_elements_locators(self.INBOX_MESSAGES_LOCATORS["all_unread_messages"])
Loading