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 refactor flows & classes belonging to the messaging system #6238

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
@@ -1,48 +1,49 @@
from playwright.sync_api import Page
from playwright_tests.core.utilities import Utilities
from playwright_tests.pages.messaging_system_pages.inbox_page import InboxPage
from playwright_tests.pages.messaging_system_pages.new_message import NewMessagePage
from playwright_tests.pages.messaging_system_pages.sent_messages import SentMessagePage


class MessagingSystemFlows(Utilities, NewMessagePage, SentMessagePage, InboxPage):
class MessagingSystemFlows:
def __init__(self, page: Page):
super().__init__(page)
self.new_message_page = NewMessagePage(page)
self.sent_message_page = SentMessagePage(page)
self.inbox_page = InboxPage(page)

# Send message form with data flow.
def complete_send_message_form_with_data(self,
recipient_username='',
message_body='',
submit_message=True):
if recipient_username != '' and not isinstance(recipient_username, list):
super()._type_into_new_message_to_input_field(recipient_username)
super()._click_on_a_searched_user(recipient_username)
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 isinstance(recipient_username, list):
for recipient in recipient_username:
super()._type_into_new_message_to_input_field(recipient)
super()._click_on_a_searched_user(recipient)
self.new_message_page.type_into_new_message_to_input_field(recipient)
self.new_message_page.click_on_a_searched_user(recipient)

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

if submit_message:
super()._click_on_new_message_send_button()
self.new_message_page.click_on_new_message_send_button()

def delete_message_flow(self, username='',
excerpt='',
delete_message=True,
from_sent_list=False,
from_inbox_list=False):
if from_sent_list and username != '':
super()._click_on_sent_message_delete_button_by_user(username)
self.sent_message_page.click_on_sent_message_delete_button_by_user(username)
elif from_sent_list and excerpt != '':
super()._click_on_sent_message_delete_button_by_excerpt(excerpt)
self.sent_message_page.click_on_sent_message_delete_button_by_excerpt(excerpt)

if from_inbox_list and username != '':
super()._click_on_inbox_message_delete_button_by_username(username)
self.inbox_page.click_on_inbox_message_delete_button_by_username(username)
elif from_inbox_list and excerpt != '':
super()._click_on_inbox_message_delete_button_by_excerpt(excerpt)
self.inbox_page.click_on_inbox_message_delete_button_by_excerpt(excerpt)

if delete_message:
super()._click_on_delete_page_delete_button()
self.sent_message_page.click_on_delete_page_delete_button()
120 changes: 60 additions & 60 deletions playwright_tests/pages/messaging_system_pages/inbox_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ def __init__(self, page: Page):
# Breadcrumb actions.

# Inbox page scam alert actions.
def _get_text_inbox_scam_alert_banner_text(self) -> str:
return super()._get_text_of_element(self.__inbox_page_scam_alert_banner_text)
def get_text_inbox_scam_alert_banner_text(self) -> str:
return self._get_text_of_element(self.__inbox_page_scam_alert_banner_text)

def _click_on_inbox_scam_alert_close_button(self):
super()._click(self.__inbox_page_scam_alert_close_button)
def click_on_inbox_scam_alert_close_button(self):
self._click(self.__inbox_page_scam_alert_close_button)

# Inbox page actions.
def _get_text_inbox_page_message_banner_text(self) -> str:
return super()._get_text_of_element(self.__inbox_page_message_action_banner)
def get_text_inbox_page_message_banner_text(self) -> str:
return self._get_text_of_element(self.__inbox_page_message_action_banner)

def _get_text_of_inbox_page_main_header(self) -> str:
return super()._get_text_of_element(self.__inbox_page_main_heading)
def get_text_of_inbox_page_main_header(self) -> str:
return self._get_text_of_element(self.__inbox_page_main_heading)

def _get_text_of_inbox_no_message_header(self) -> str:
return super()._get_text_of_element(self.__inbox_no_messages_text)
def get_text_of_inbox_no_message_header(self) -> str:
return self._get_text_of_element(self.__inbox_no_messages_text)

# Inbox messages actions.
def _get_inbox_message_subject(self, username: str) -> str:
return super()._get_text_of_element((
def get_inbox_message_subject(self, username: str) -> str:
return self._get_text_of_element((
f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../..//"
f"a[@class='read']"
))
Expand All @@ -62,93 +62,93 @@ def _get_inbox_message_subject(self, username: str) -> str:
# 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):
super()._click((
def click_on_inbox_message_delete_button_by_username(self, username: str):
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):
super()._click(f"//div[@class='email-cell excerpt']/a[normalize-space(text())='{excerpt}']"
f"/../..//a[@class='delete']")
def click_on_inbox_message_delete_button_by_excerpt(self, excerpt: str):
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):
super()._click(self.__inbox_new_message_button)
def click_on_inbox_new_message_button(self):
self._click(self.__inbox_new_message_button)

def _click_on_inbox_mark_selected_as_read_button(self):
super()._click(self.__inbox_mark_selected_as_read_button)
def click_on_inbox_mark_selected_as_read_button(self):
self._click(self.__inbox_mark_selected_as_read_button)

def _click_on_inbox_delete_selected_button(self):
super()._click(self.__inbox_delete_selected_button)
def click_on_inbox_delete_selected_button(self):
self._click(self.__inbox_delete_selected_button)

def _click_on_inbox_message_sender_username(self, username: str):
super()._click(f"//div[@class='email-cell from']//a[contains(text(),'{username}')]")
def click_on_inbox_message_sender_username(self, username: str):
self._click(f"//div[@class='email-cell from']//a[contains(text(),'{username}')]")

def _inbox_message_select_checkbox_element(self, excerpt='') -> list[ElementHandle]:
def inbox_message_select_checkbox_element(self, excerpt='') -> list[ElementHandle]:
if excerpt != '':
return super()._get_element_handles(f"//div[@class='email-cell excerpt']"
f"/a[normalize-space(text())='{excerpt}']/../.."
f"/div[@class='email-cell check']/input")
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 super()._get_element_handles(self.__inbox_delete_checkbox)
return self._get_element_handles(self.__inbox_delete_checkbox)

def _click_on_inbox_message_subject(self, username: str):
super()._click((f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../.."
f"//a[@class='read']"))
def click_on_inbox_message_subject(self, username: str):
self._click((f"//div[@class='email-cell from']//a[contains(text(),'{username}')]/../.."
f"//a[@class='read']"))

def _click_on_delete_page_delete_button(self):
super()._click(self.__inbox_delete_page_delete_button)
def click_on_delete_page_delete_button(self):
self._click(self.__inbox_delete_page_delete_button)

def _click_on_delete_page_cancel_button(self):
def click_on_delete_page_cancel_button(self):
# Hitting the "Enter" button instead of click due to an issue (the banner does not close
# on click)
super()._press_a_key(self.__inbox_delete_page_cancel_button, 'Enter')
self._press_a_key(self.__inbox_delete_page_cancel_button, 'Enter')

def _is_no_message_header_displayed(self) -> bool:
return super()._is_element_visible(self.__inbox_no_messages_text)
def is_no_message_header_displayed(self) -> bool:
return self._is_element_visible(self.__inbox_no_messages_text)

def _inbox_message_banner(self) -> Locator:
return super()._get_element_locator(self.__inbox_page_scam_alert_banner_text)
def inbox_message_banner(self) -> Locator:
return self._get_element_locator(self.__inbox_page_scam_alert_banner_text)

def _inbox_message(self, username: str) -> Locator:
return super()._get_element_locator(f"//div[@class='email-cell from']//a[contains(text(),"
f"'{username}')]")
def inbox_message(self, username: str) -> Locator:
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:
return super()._get_element_locator(f"//div[@class='email-cell excerpt']/a[normalize-space"
f"(text())='{excerpt}']")
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]:
return super()._get_element_handles(f"//div[@class='email-cell excerpt']/a[normalize-space"
f"(text())='{excerpt}']")
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 super()._is_element_visible(self.__inbox_messages_section)
def are_inbox_messages_displayed(self) -> bool:
return self._is_element_visible(self.__inbox_messages_section)

def _delete_all_inbox_messages(self):
inbox_messages_count = super()._get_element_handles(self.__inbox_messages)
def delete_all_inbox_messages(self):
inbox_messages_count = self._get_element_handles(self.__inbox_messages)
for i in range(len(inbox_messages_count)):
inbox_elements_delete_button = super()._get_element_handles(
inbox_elements_delete_button = self._get_element_handles(
self.__inbox_messages_delete_button)
delete_button = inbox_elements_delete_button[i]

delete_button.click()
self._click_on_delete_page_delete_button()
self.click_on_delete_page_delete_button()

def _delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):
def delete_all_inbox_messages_via_delete_selected_button(self, excerpt=''):
if excerpt != '':
inbox_messages_count = self._inbox_message_element_handles(excerpt)
else:
inbox_messages_count = super()._get_element_handles(self.__inbox_messages)
inbox_messages_count = self._get_element_handles(self.__inbox_messages)
counter = 0
for i in range(len(inbox_messages_count)):
if excerpt != '':
inbox_checkbox = self._inbox_message_select_checkbox_element(excerpt)
inbox_checkbox = self.inbox_message_select_checkbox_element(excerpt)
else:
inbox_checkbox = self._inbox_message_select_checkbox_element()
inbox_checkbox = self.inbox_message_select_checkbox_element()
element = inbox_checkbox[counter]
element.click()
counter += 1

self._click_on_inbox_delete_selected_button()
self._click_on_delete_page_delete_button()
self.click_on_inbox_delete_selected_button()
self.click_on_delete_page_delete_button()
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ def __init__(self, page: Page):
super().__init__(page)

# Messaging system navbar actions.
def _click_on_messaging_system_navbar_inbox(self):
super()._click(self.__messaging_system_user_navbar_inbox_option)
def click_on_messaging_system_navbar_inbox(self):
self._click(self.__messaging_system_user_navbar_inbox_option)

def _click_on_messaging_system_nav_sent_messages(self):
super()._click(self.__messaging_system_user_navbar_sent_messages_option)
def click_on_messaging_system_nav_sent_messages(self):
self._click(self.__messaging_system_user_navbar_sent_messages_option)

def _click_on_messaging_system_nav_new_message(self):
super()._click(self.__messaging_system_user_navbar_new_message_option)
def click_on_messaging_system_nav_new_message(self):
self._click(self.__messaging_system_user_navbar_new_message_option)

# Need to add logic for fetching the background color of selected navbar elements
def _get_inbox_navbar_element(self) -> Locator:
return super()._get_element_locator(self.__messaging_system_user_navbar_inbox_option)
def get_inbox_navbar_element(self) -> Locator:
return self._get_element_locator(self.__messaging_system_user_navbar_inbox_option)

def _get_sent_messages_navbar_element(self) -> Locator:
return super()._get_element_locator(
def get_sent_messages_navbar_element(self) -> Locator:
return self._get_element_locator(
self.__messaging_system_user_navbar_sent_messages_option)

def _get_new_message_navbar_element(self) -> Locator:
return super()._get_element_locator(self.__messaging_system_user_navbar_new_message_option)
def get_new_message_navbar_element(self) -> Locator:
return self._get_element_locator(self.__messaging_system_user_navbar_new_message_option)
Loading