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 custom xpath cleanup #6022

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
- Xpath Cleanup
  • Loading branch information
emilghittasv committed May 21, 2024
commit 7528616fe83788e86db90e9c88e08c34c9607353
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def _get_in_progress_item_label(self) -> str:
return super()._get_text_of_element(self.__in_progress_item_label)

def _click_on_a_particular_completed_milestone(self, milestone_name: str):
xpath = f'//span[@class="progress--label" and text()="{milestone_name}"]/../..'
super()._click(xpath)
super()._click(f'//span[@class="progress--label" and text()="{milestone_name}"]/../..')

# Question subject actions.
def _get_value_of_subject_input_field(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ def _get_all_product_card_titles(self) -> list[str]:
return super()._get_text_of_elements(self.__product_cards_titles)

def _get_product_card_subtitle(self, card_name: str) -> str:
xpath = (f"//a[normalize-space(text()) = '{card_name}']/..//following-sibling::p["
f"@class='card--desc']")
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//a[normalize-space(text()) = '{card_name}']/..//"
f"following-sibling::p[@class='card--desc']")

def _click_on_a_particular_card(self, card_name: str):
xpath = f"//h3[@class='card--title']/a[normalize-space(text())='{card_name}']"
super()._click(xpath)
super()._click(f"//h3[@class='card--title']/a[normalize-space(text())='{card_name}']")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def _get_current_milestone_text(self) -> str:

# Featured article actions.
def _click_on_a_featured_article_card(self, card_name: str):
xpath = f'//h2[contains(text(),"Featured Articles")]/../..//a[text()="{card_name}"]'
super()._click(xpath)
super()._click(f'//h2[contains(text(),"Featured Articles")]/../..//'
f'a[text()="{card_name}"]')

def _get_all_featured_articles_titles(self) -> list[str]:
return super()._get_text_of_elements(self.__featured_articles_cards)
Expand All @@ -76,9 +76,8 @@ def _is_featured_article_section_displayed(self) -> bool:

# Popular topic actions.
def _click_on_a_popular_topic_card(self, card_name: str):
xpth = (f"//h2[contains(text(),'Popular Topics')]/../..//a[normalize-space(text()) = "
f"'{card_name}']")
super()._click(xpth)
super()._click(f"//h2[contains(text(),'Popular Topics')]/../..//"
f"a[normalize-space(text()) = '{card_name}']")

def _get_popular_topics(self) -> list[str]:
return super()._get_text_of_elements(self.__popular_topics_cards)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ def _get_page_title(self) -> str:
return super()._get_text_of_element(self.__page_title)

def _get_a_particular_article_locator(self, article_title: str):
xpath = f"//h2[@class='sumo-card-heading']/a[normalize-space(text())='{article_title}']"
return super()._get_element_locator(xpath)
return super()._get_element_locator(f"//h2[@class='sumo-card-heading']/a[normalize-space"
f"(text())='{article_title}']")

# Navbar actions.
def _get_selected_navbar_option(self) -> str:
return super()._get_text_of_element(self.__selected_nav_link)

def _click_on_a_navbar_option(self, option_name: str):
xpath = f'//a[@data-event-action="topic sidebar" and contains(text(), "{option_name}")]'
super()._click(xpath)
super()._click(f'//a[@data-event-action="topic sidebar" and contains(text(),'
f' "{option_name}")]')

def _get_navbar_links_text(self) -> list[str]:
return super()._get_text_of_elements(self.__navbar_links)

def _get_navbar_option_link(self, option_name: str) -> str:
xpath = f'//a[@data-event-action="topic sidebar" and contains(text(), "{option_name}")]'
return super()._get_element_attribute_value(xpath, "href")
return super()._get_element_attribute_value(f'//a[@data-event-action="topic sidebar" '
f'and contains(text(), "{option_name}")]',
"href")

# AAQ section actions.
def _get_aaq_subheading_text(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _click_on_the_show_all_questions_option(self):

# Question list actions
def _get_all_question_list_tags(self, question_id: str) -> list[str]:
xpath = f"//article[@id='{question_id}']//li[@class='tag']"
question_tags = super()._get_text_of_elements(xpath)
question_tags = super()._get_text_of_elements(f"//article[@id='{question_id}']//"
f"li[@class='tag']")
return question_tags

def _extract_question_ids(self) -> list[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ def _click_on_all_products_support_forum_button(self):

# Product cards actions.
def _click_on_a_particular_product_card(self, card_name: str):
xpath = f"//strong[text()='{card_name}']"
super()._click(xpath)
super()._click(f"//strong[text()='{card_name}']")

def _get_product_card_titles_list(self) -> list[str]:
return super()._get_text_of_elements(self.__product_card_titles)

def _get_card_description_text(self, card_title: str) -> str:
xpath = f"//strong[text()='{card_title}']/../../following-sibling::p"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//strong[text()='{card_title}']/../../"
f"following-sibling::p")
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def __init__(self, page: Page):
super().__init__(page)

def _is_title_for_article_discussion_displayed(self, article_title: str) -> Locator:
xpath = f"//td[@class='title']/a[text()='{article_title}']"
return super()._get_element_locator(xpath)
return super()._get_element_locator(f"//td[@class='title']/a[text()='{article_title}']")
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,48 @@ def __init__(self, page: Page):

# KB Dashboard actions
def _get_a_particular_article_title_locator(self, article_name: str) -> Locator:
xpath = f"//td/a[text()='{article_name}']"
return super()._get_element_locator(xpath)
return super()._get_element_locator(f"//td/a[text()='{article_name}']")

def _click_on_article_title(self, article_name: str):
xpath = f"//td/a[text()='{article_name}']"
super()._click(xpath)
super()._click(f"//td/a[text()='{article_name}']")

def _get_a_particular_article_status(self, article_name: str) -> str:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'status ')]")
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains(@class,'status ')]")

def _get_needs_update_status(self, article_name: str) -> str:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'needs-update')]")
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains(@class, "
f"'needs-update')]")

def _is_needs_change_empty(self, article_name: str) -> bool:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'needs-update')]")
return super()._is_element_empty(xpath)
return super()._is_element_empty(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains(@class,'needs-update')]")

def _get_ready_for_l10n_status(self, article_name: str) -> str:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'ready-for-l10n')]")
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains"
f"(@class,'ready-for-l10n')]")

def _get_stale_status(self, article_name: str) -> str:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'stale ')]")
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains(@class,'stale ')]")

def _is_stale_status_empty(self, article_name: str) -> bool:
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td[contains(@class,"
f"'stale ')]")
return super()._is_element_empty(xpath)
return super()._is_element_empty(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td[contains(@class,'stale ')]")

def _get_existing_expiry_date(self, article_name: str) -> str:
xpath = f"//td/a[text()='{article_name}']/../following-sibling::td/time"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td/time")

def _get_expiry_date_locator(self, article_name: str) -> Locator:
xpath = f"//td/a[text()='{article_name}']/../following-sibling::td/time"
return super()._get_element_locator(xpath)
return super()._get_element_locator(f"//td/a[text()='{article_name}']/../"
f"following-sibling::td/time")

def _click_on_show_translations_option(self, article_name: str):
xpath = (f"//td/a[text()='{article_name}']/../following-sibling::td/a[contains(text(),"
f"'Show translations')]")
super()._click(xpath)
super()._click(f"//td/a[text()='{article_name}']/../following-sibling::td/"
f"a[contains(text(),'Show translations')]")

def _click_on_the_complete_overview_link(self):
super()._click(self.__complete_overview_link)
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def _get_image_in_documents_list_items_text(self) -> list[str]:
return super()._get_text_of_elements(self.__image_in_documents_list)

def _click_on_a_linked_in_document(self, document_name: str):
xpath = f"//div[@class='documents']//li/a[text()='{document_name}']"
super()._click(xpath)
super()._click(f"//div[@class='documents']//li/a[text()='{document_name}']")

def _click_on_delete_this_image_button(self):
super()._click(self.__delete_this_image_button)
Expand Down Expand Up @@ -89,10 +88,9 @@ def _click_on_upload_media_button(self):
super()._click(self.__upload_media_button)

def _select_media_file_from_list(self, media_file_name: str):
xpath = f"//ol[@id='media-list']/li/a[@title='{media_file_name}']"
# We need to wait a bit so that the list finishes to update in case of search.
super()._wait_for_given_timeout(1000)
super()._click(xpath)
super()._click(f"//ol[@id='media-list']/li/a[@title='{media_file_name}']")

def _click_on_insert_media_button(self):
super()._click(self.__insert_media_button)
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,48 @@ def __init__(self, page: Page):
super().__init__(page)

def _get_flagged_question_locator(self, question_title) -> Locator:
xpath = f"//p[text()='{question_title}']"
return super()._get_element_locator(xpath)
return super()._get_element_locator(f"//p[text()='{question_title}']")

def _get_flag_reason(self, question_title: str) -> str:
xpath = f"//p[text()='{question_title}']/../preceding-sibling::hgroup/h2"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//p[text()='{question_title}']/../"
f"preceding-sibling::hgroup/h2")

def _get_flagged_question_content(self, question_title: str) -> str:
xpath = f"//p[text()='{question_title}']/following-sibling::div[@class='content']/p"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//p[text()='{question_title}']/"
f"following-sibling::div[@class='content']/p")

def _get_created_by_link_text(self, question_title: str) -> str:
xpath = f"//p[text()='{question_title}']/following-sibling::p[@class='created']/a"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//p[text()='{question_title}']/"
f"following-sibling::p[@class='created']/a")

def _click_created_by_link(self, question_title: str):
xpath = f"//p[text()='{question_title}']/following-sibling::p[@class='created']/a"
super()._click(xpath)
super()._click(f"//p[text()='{question_title}']/"
f"following-sibling::p[@class='created']/a")

def _get_flagged_by_link_text(self, question_title: str) -> str:
xpath = f"//p[text()='{question_title}']/following-sibling::p[@class='flagged']/a"
return super()._get_text_of_element(xpath)
return super()._get_text_of_element(f"//p[text()='{question_title}']/"
f"following-sibling::p[@class='flagged']/a")

def _click_flagged_by_link(self, question_title: str):
xpath = f"//p[text()='{question_title}']/following-sibling::p[@class='flagged']/a"
super()._click(xpath)
super()._click(f"//p[text()='{question_title}']/"
f"following-sibling::p[@class='flagged']/a")

def _click_take_action_view_option(self, question_title: str):
xpath = f"//p[text()='{question_title}']/following-sibling::div/a[text()='View']"
super()._click(xpath)
super()._click(f"//p[text()='{question_title}']/following-sibling::div/a[text()='View']")

def _click_take_action_edit_option(self, question_title: str):
xpath = f"//p[text()='{question_title}']/following-sibling::div/a[text()='Edit']"
super()._click(xpath)
super()._click(f"//p[text()='{question_title}']/following-sibling::div/a[text()='Edit']")

def _click_take_action_delete_option(self, question_title: str):
xpath = f"//p[text()='{question_title}']/following-sibling::div/a[text()='Delete']"
super()._click(xpath)
super()._click(f"//p[text()='{question_title}']/following-sibling::div/a[text()='Delete']")

def _select_update_status_option(self, question_title: str, select_value: str):
xpath = f"//p[text()='{question_title}']/following-sibling::form/select"
super()._select_option_by_label(xpath, select_value)
super()._select_option_by_label(f"//p[text()='{question_title}']/"
f"following-sibling::form/select", select_value)

def _click_on_the_update_button(self, questions_title: str):
xpath = f"//p[text()='{questions_title}']/following-sibling::form/input[@value='Update']"
super()._click(xpath)
super()._click(f"//p[text()='{questions_title}']/following-sibling::form/"
f"input[@value='Update']")

def _click_view_all_deactivated_users_button(self):
super()._click(self.__view_all_deactivated_users_button)
Loading