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 kb article threads flow refactor #6259

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 @@ -9,41 +9,45 @@
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage


class KbThreads(Utilities, KBArticleDiscussionPage, KBArticlePage):
class KbThreads:
def __init__(self, page: Page):
super().__init__(page)
self.page = page
self.utilities = Utilities(page)
self.kb_article_discussion_page = KBArticleDiscussionPage(page)
self.kb_article_page = KBArticlePage(page)

def delete_article_thread(self, thread_id: str, confirm_deletion=True):
super()._click_on_a_particular_thread(thread_id)
super()._click_on_delete_this_thread_option()
self.kb_article_discussion_page.click_on_a_particular_thread(thread_id)
self.kb_article_discussion_page.click_on_delete_this_thread_option()

if confirm_deletion:
super()._click_on_delete_this_thread_reply_confirmation_button()
self.kb_article_discussion_page.click_on_delete_this_thread_reply_confirmation_button(
)

def add_new_kb_discussion_thread(self, title='') -> [dict[str, Any]]:
super().click_on_editing_tools_discussion_option()
article_discussion_url = super().get_url()
super()._click_on_post_a_new_thread_option()
self.kb_article_page.click_on_editing_tools_discussion_option()
article_discussion_url = self.utilities.get_page_url()
self.kb_article_discussion_page.click_on_post_a_new_thread_option()
if title == '':
thread_title = (super().kb_new_thread_test_data['new_thread_title'] + super()
.generate_random_number(0, 5000))
thread_title = (self.utilities.kb_new_thread_test_data['new_thread_title'] + self
.utilities.generate_random_number(0, 5000))
else:
thread_title = (title + super()
thread_title = (title + self.utilities
.generate_random_number(0, 5000))
thread_body = super().kb_new_thread_test_data['new_thread_body']
thread_body = self.utilities.kb_new_thread_test_data['new_thread_body']

# Adding text to the title field.
super()._add_text_to_new_thread_title_field(thread_title)
self.kb_article_discussion_page.add_text_to_new_thread_title_field(thread_title)

# Adding text to the body field.
super()._add_text_to_new_thread_body_input_field(thread_body)
self.kb_article_discussion_page.add_text_to_new_thread_body_input_field(thread_body)

# Clicking on the post a new thread option.
super()._click_on_submit_new_thread_button()
self.kb_article_discussion_page.click_on_submit_new_thread_button()

# Fetching the article url & the thread id from the url.
thread_url = self.page.url
thread_id = str(super().number_extraction_from_string_endpoint(
thread_id = str(self.utilities.number_extraction_from_string_endpoint(
KBArticlePageMessages.KB_ARTICLE_DISCUSSIONS_ENDPOINT, thread_url)
)

Expand All @@ -56,27 +60,29 @@ def add_new_kb_discussion_thread(self, title='') -> [dict[str, Any]]:
}

def _edit_article_thread(self, thread_title="", submit_edit=True):
super()._click_on_edit_this_thread_option()
super()._add_text_to_edit_article_thread_title_field(thread_title)
self.kb_article_discussion_page.click_on_edit_this_thread_option()
self.kb_article_discussion_page.add_text_to_edit_article_thread_title_field(thread_title)

if submit_edit:
super()._click_on_edit_article_thread_update_button()
self.kb_article_discussion_page.click_on_edit_article_thread_update_button()
else:
super()._click_on_edit_article_thread_cancel_button()
self.kb_article_discussion_page.click_on_edit_article_thread_cancel_button()

def post_reply_to_thread(self, text: str, post_reply=True) -> dict[str, Any]:
super()._fill_the_thread_post_a_reply_textarea(text)
self.kb_article_discussion_page.fill_the_thread_post_a_reply_textarea(text)

if post_reply:
super()._click_on_thread_post_reply_button()
self.kb_article_discussion_page.click_on_thread_post_reply_button()

return {
"reply_id": super()._get_thread_reply_id(super().get_url())
"reply_id": self.kb_article_discussion_page.get_thread_reply_id
(self.utilities.get_page_url())
}

def delete_reply_to_thread(self, reply_id: str, submit_deletion=True):
super()._click_on_dotted_menu_for_a_certain_reply(reply_id)
super()._click_on_delete_this_thread_reply(reply_id)
self.kb_article_discussion_page.click_on_dotted_menu_for_a_certain_reply(reply_id)
self.kb_article_discussion_page.click_on_delete_this_thread_reply(reply_id)

if submit_deletion:
super()._click_on_delete_this_thread_reply_confirmation_button()
self.kb_article_discussion_page.click_on_delete_this_thread_reply_confirmation_button(
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,145 +51,145 @@ def __init__(self, page: Page):
super().__init__(page)

# Edit thread page actions
def _get_edit_this_thread_locator(self) -> Locator:
return super()._get_element_locator(self.__article_thread_edit_this_thread)
def get_edit_this_thread_locator(self) -> Locator:
return self._get_element_locator(self.__article_thread_edit_this_thread)

def _click_on_edit_this_thread_option(self):
super()._click(self.__article_thread_edit_this_thread)
def click_on_edit_this_thread_option(self):
self._click(self.__article_thread_edit_this_thread)

def _add_text_to_edit_article_thread_title_field(self, text: str):
super()._clear_field(self.__edit_article_thread_title_field)
super()._fill(self.__edit_article_thread_title_field, text)
def add_text_to_edit_article_thread_title_field(self, text: str):
self._clear_field(self.__edit_article_thread_title_field)
self._fill(self.__edit_article_thread_title_field, text)

def _click_on_edit_article_thread_cancel_button(self):
super()._click(self.__edit_article_thread_cancel_button)
def click_on_edit_article_thread_cancel_button(self):
self._click(self.__edit_article_thread_cancel_button)

def _click_on_edit_article_thread_update_button(self):
super()._click(self.__edit_article_thread_update_thread_button)
def click_on_edit_article_thread_update_button(self):
self._click(self.__edit_article_thread_update_thread_button)

# Filter actions.
def _click_on_article_thread_author_replies_filter(self):
super()._click(self.__article_thread_author_filter)
def click_on_article_thread_author_replies_filter(self):
self._click(self.__article_thread_author_filter)

def _click_on_article_thread_replies_filter(self):
super()._click(self.__article_thread_replies_filter)
def click_on_article_thread_replies_filter(self):
self._click(self.__article_thread_replies_filter)

# Post a new thread button action.
def _click_on_post_a_new_thread_option(self):
super()._click(self.__post_a_new_thread_option)
def click_on_post_a_new_thread_option(self):
self._click(self.__post_a_new_thread_option)

def _click_on_thread_post_reply_button(self):
super()._click(self.__thread_post_a_new_reply_button)
def click_on_thread_post_reply_button(self):
self._click(self.__thread_post_a_new_reply_button)

def _get_thread_reply_id(self, url: str) -> str:
def get_thread_reply_id(self, url: str) -> str:
return re.search(r'post-(\d+)', url).group(0)

# Actions related to posting a new thread.
def _add_text_to_new_thread_title_field(self, text: str):
super()._fill(self.__new_thread_title_input_field, text)
def add_text_to_new_thread_title_field(self, text: str):
self._fill(self.__new_thread_title_input_field, text)

def _clear_new_thread_title_field(self):
super()._clear_field(self.__new_thread_title_input_field)
def clear_new_thread_title_field(self):
self._clear_field(self.__new_thread_title_input_field)

def _add_text_to_new_thread_body_input_field(self, text: str):
super()._fill(self.__new_thread_body_input_field, text)
def add_text_to_new_thread_body_input_field(self, text: str):
self._fill(self.__new_thread_body_input_field, text)

def _clear_new_thread_body_field(self):
super()._clear_field(self.__new_thread_body_input_field)
def clear_new_thread_body_field(self):
self._clear_field(self.__new_thread_body_input_field)

def _click_on_cancel_new_thread_button(self):
super()._click(self.__new_thread_cancel_button)
def click_on_cancel_new_thread_button(self):
self._click(self.__new_thread_cancel_button)

def _click_on_submit_new_thread_button(self):
super()._click(self.__new_thread_submit_button)
def click_on_submit_new_thread_button(self):
self._click(self.__new_thread_submit_button)

def _get_posted_thread_locator(self, thread_id: str) -> Locator:
return super()._get_element_locator(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]")
def get_posted_thread_locator(self, thread_id: str) -> Locator:
return self._get_element_locator(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]")

def _get_thread_by_title_locator(self, thread_title: str) -> Locator:
return super()._get_element_locator(f"//tr[@class='threads']/td[@class='title']/"
f"a[text()='{thread_title}']")
def get_thread_by_title_locator(self, thread_title: str) -> Locator:
return self._get_element_locator(f"//tr[@class='threads']/td[@class='title']/"
f"a[text()='{thread_title}']")

def _click_on_a_particular_thread(self, thread_id: str):
super()._click(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]")
def click_on_a_particular_thread(self, thread_id: str):
self._click(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]")

# Actions related to thread content
def _get_thread_title_text(self) -> str:
return super()._get_text_of_element(self.__thread_body_content_title)
def get_thread_title_text(self) -> str:
return self._get_text_of_element(self.__thread_body_content_title)

def _get_locked_article_status(self) -> Locator:
return super()._get_element_locator(self.__article_thread_locked_status)
def get_locked_article_status(self) -> Locator:
return self._get_element_locator(self.__article_thread_locked_status)

def _get_lock_this_article_thread_option_text(self) -> str:
return super()._get_text_of_element(self.__lock_this_thread)
def get_lock_this_article_thread_option_text(self) -> str:
return self._get_text_of_element(self.__lock_this_thread)

def _get_lock_this_article_thread_locator(self) -> Locator:
return super()._get_element_locator(self.__lock_this_thread)
def get_lock_this_article_thread_locator(self) -> Locator:
return self._get_element_locator(self.__lock_this_thread)

def _click_on_lock_this_article_thread_option(self):
super()._click(self.__lock_this_thread)
def click_on_lock_this_article_thread_option(self):
self._click(self.__lock_this_thread)

def _get_sticky_this_thread_locator(self) -> Locator:
return super()._get_element_locator(self.__sticky_this_thread)
def get_sticky_this_thread_locator(self) -> Locator:
return self._get_element_locator(self.__sticky_this_thread)

def _get_text_of_sticky_this_thread_option(self) -> str:
return super()._get_text_of_element(self.__sticky_this_thread)
def get_text_of_sticky_this_thread_option(self) -> str:
return self._get_text_of_element(self.__sticky_this_thread)

def _get_sticky_this_thread_status_locator(self) -> Locator:
return super()._get_element_locator(self.__article_thread_sticky_status)
def get_sticky_this_thread_status_locator(self) -> Locator:
return self._get_element_locator(self.__article_thread_sticky_status)

def _click_on_sticky_this_thread_option(self):
super()._click(self.__sticky_this_thread)
def click_on_sticky_this_thread_option(self):
self._click(self.__sticky_this_thread)

def _get_thread_post_a_reply_textarea_field(self) -> Locator:
return super()._get_element_locator(self.__thread_post_a_reply_textarea_field)
def get_thread_post_a_reply_textarea_field(self) -> Locator:
return self._get_element_locator(self.__thread_post_a_reply_textarea_field)

def _fill_the_thread_post_a_reply_textarea(self, text: str):
super()._fill(self.__thread_post_a_reply_textarea_field, text)
def fill_the_thread_post_a_reply_textarea(self, text: str):
self._fill(self.__thread_post_a_reply_textarea_field, text)

def _get_thread_page_counter_replies_text(self) -> str:
return super()._get_text_of_element(self.__thread_page_replies_counter)
def get_thread_page_counter_replies_text(self) -> str:
return self._get_text_of_element(self.__thread_page_replies_counter)

def _get_thread_page_replied_by_text(self) -> str:
return super()._get_text_of_element(self.__thread_page_last_reply_by_text)
def get_thread_page_replied_by_text(self) -> str:
return self._get_text_of_element(self.__thread_page_last_reply_by_text)

# Article discussions page content actions
def _get_article_discussions_thread_counter(self, thread_id: str) -> str:
return super()._get_text_of_element(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]/../"
f"following-sibling::td[@class='replies']")
def get_article_discussions_thread_counter(self, thread_id: str) -> str:
return self._get_text_of_element(f"//tr[@class='threads']/td[@class='title']//"
f"a[contains(@href, '{thread_id}')]/../"
f"following-sibling::td[@class='replies']")

def _get_all_article_threads_titles(self) -> list[str]:
return super()._get_text_of_elements(self.__all_article_threads_titles)
def get_all_article_threads_titles(self) -> list[str]:
return self._get_text_of_elements(self.__all_article_threads_titles)

def _get_all_article_threads_authors(self) -> list[str]:
return super()._get_text_of_elements(self.__all_article_threads_authors)
def get_all_article_threads_authors(self) -> list[str]:
return self._get_text_of_elements(self.__all_article_threads_authors)

def _get_all_article_threads_replies(self) -> list[str]:
return super()._get_text_of_elements(self.__all_article_thread_replies)
def get_all_article_threads_replies(self) -> list[str]:
return self._get_text_of_elements(self.__all_article_thread_replies)

def _get_text_of_locked_article_thread_text(self) -> str:
return super()._get_text_of_element(self.__article_thread_locked_message)
def get_text_of_locked_article_thread_text(self) -> str:
return self._get_text_of_element(self.__article_thread_locked_message)

def _get_text_of_locked_article_thread_locator(self) -> Locator:
return super()._get_element_locator(self.__article_thread_locked_message)
def get_text_of_locked_article_thread_locator(self) -> Locator:
return self._get_element_locator(self.__article_thread_locked_message)

# Actions related to thread replies.
def _click_on_dotted_menu_for_a_certain_reply(self, thread_id: str):
super()._click(f"//li[@id='{thread_id}']//span[@class='icon-button is-summary']//button")
def click_on_dotted_menu_for_a_certain_reply(self, thread_id: str):
self._click(f"//li[@id='{thread_id}']//span[@class='icon-button is-summary']//button")

def _click_on_delete_this_thread_option(self):
super()._click(self.__delete_thread)
def click_on_delete_this_thread_option(self):
self._click(self.__delete_thread)

def _click_on_edit_this_thread_reply(self, thread_id: str):
super()._click(f"//li[@id='{thread_id}']//div[@class='mzp-c-menu-list is-details']//"
f"a[text()='Edit this post']")
def click_on_edit_this_thread_reply(self, thread_id: str):
self._click(f"//li[@id='{thread_id}']//div[@class='mzp-c-menu-list is-details']//"
f"a[text()='Edit this post']")

def _click_on_delete_this_thread_reply(self, thread_id: str):
super()._click(f"//li[@id='{thread_id}']//div[@class='mzp-c-menu-list is-details']//"
f"a[text()='Delete this post']")
def click_on_delete_this_thread_reply(self, thread_id: str):
self._click(f"//li[@id='{thread_id}']//div[@class='mzp-c-menu-list is-details']//"
f"a[text()='Delete this post']")

def _click_on_delete_this_thread_reply_confirmation_button(self):
super()._click(self.__delete_thread_reply_confirmation_page_button)
def click_on_delete_this_thread_reply_confirmation_button(self):
self._click(self.__delete_thread_reply_confirmation_page_button)
Loading