Skip to content

Commit

Permalink
Merge pull request #6313 from emilghittasv/playwright-improve-explore…
Browse files Browse the repository at this point in the history
…-by-topic

Playwright improve and document the explore_by_topic page object
  • Loading branch information
emilghittasv authored Oct 24, 2024
2 parents 7305114 + fc2f23b commit 8e76a2e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 83 deletions.
143 changes: 83 additions & 60 deletions playwright_tests/pages/explore_help_articles/explore_by_topic_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,108 @@


class ExploreByTopicPage(BasePage):
"""
Locators belonging to the header section.
"""
__explore_by_topic_page_header = "//div[@class='documents-product-title']/h1"

"""
Locators belonging to the listed KB articles.
"""
__article_metadata_info = "//div[@id='document_metadata']//span[@class='tooltip']"

"""
Locators belonging to the side-navbar section.
"""
__filter_by_product_dropdown = "//select[@id='products-topics-dropdown']"
__filter_by_product_dropdown_selected_option = ("//select[@id='products-topics-dropdown"
"']/option[@selected]")
__filter_by_product_dropdown_options = "//select[@id='products-topics-dropdown']/option"
__all_topics_side_navbar_options = "//ul[@class='sidebar-nav--list']/li/a"
__all_topics_selected_option = ("//ul[@class='sidebar-nav--list']/li/a[contains(@class, "
"'selected')]")
__AAQ_widget_continue_button = ("//div[@class='aaq-widget card is-inverse elevation-01 "
"text-center radius-md']/a")
__AAQ_widget_text = ("//div[@class='aaq-widget card is-inverse elevation-01 text-center "
"radius-md']/p")

"""
Locators belonging to the Volunteer card section.
"""
__volunteer_learn_more_option = "//section[@id='get-involved-button']//a"
# Locators belonging to the header section.
HEADER_SECTION_LOCATORS = {
"explore_by_topic_page_header": "//div[@class='documents-product-title']/h1"
}

# Locators belonging to the listed KB articles.
LISTED_ARTICLES_LOCATORS = {
"article_metadata_info": "//div[@id='document_metadata']//span[@class='tooltip']"
}

# Locators belonging to the page side-navbar section.
SIDE_NAVBAR_LOCATORS = {
"filter_by_product_dropdown": "//select[@id='products-topics-dropdown']",
"filter_by_product_dropdown_selected_option": "//select[@id='products-topics-dropdown']/"
"option[@selected]",
"filter_by_product_dropdown_options": "//select[@id='products-topics-dropdown']/option",
"all_topics_side_navbar_options": "//ul[@class='sidebar-nav--list']/li/a",
"all_topics_selected_option": "//ul[@class='sidebar-nav--list']/li/a[contains(@class, "
"'selected')]",
"AAQ_widget_continue_button": "//div[@class='aaq-widget card is-inverse elevation-01 text"
"-center radius-md']/a",
"AAQ_widget_text": "//div[@class='aaq-widget card is-inverse elevation-01 text-center "
"radius-md']/p"
}

# Locators belonging to the Volunteer card section.
VOLUNTEER_CARD_LOCATORS = {
"volunteer_learn_more_option": "//section[@id='get-involved-button']//a"
}

def __init__(self, page: Page):
super().__init__(page)

"""
Actions against the page header section.
"""
def _get_explore_by_topic_page_header(self) -> str:
return super()._get_text_of_element(self.__explore_by_topic_page_header)
def get_explore_by_topic_page_header(self) -> str:
"""Get the text of the page header."""
return self._get_text_of_element(self.HEADER_SECTION_LOCATORS
["explore_by_topic_page_header"])

"""
Actions against the listed KB articles.
"""
def _get_metadata_of_all_listed_articles(self) -> list[list[str]]:
elements = []
for metadata in super()._get_elements_locators(self.__article_metadata_info):
metadata_elements = super()._get_text_content_of_all_locators(metadata)
for item in metadata_elements:
split_items = [i.strip() for i in item.strip().split(',')]
elements.append(split_items)
def get_metadata_of_all_listed_articles(self) -> list[list[str]]:
"""Get the metadata of all listed articles."""
elements = [
[i.strip() for i in item.strip().split(',')]
for metadata in self._get_elements_locators(self.LISTED_ARTICLES_LOCATORS
["article_metadata_info"])
for item in self._get_text_content_of_all_locators(metadata)
]
return elements

"""
Actions against the page side-navbar section.
"""
def _get_selected_topic_side_navbar_option(self) -> str:
return super()._get_text_of_element(self.__all_topics_selected_option)

def _get_all_topics_side_navbar_options(self) -> list[str]:
return super()._get_text_of_elements(self.__all_topics_side_navbar_options)

def _click_on_a_topic_filter(self, option: str):
super()._click(f"//ul[@class='sidebar-nav--list']/li/"
f"a[normalize-space(text())='{option}']")

def _get_current_product_filter_dropdown_option(self) -> str:
option = super()._get_text_of_element(self.__filter_by_product_dropdown_selected_option)
def get_selected_topic_side_navbar_option(self) -> str:
"""Get the text of the selected topic in the side-navbar."""
return self._get_text_of_element(self.SIDE_NAVBAR_LOCATORS["all_topics_selected_option"])

def get_all_topics_side_navbar_options(self) -> list[str]:
"""Get the text of all topics in the side-navbar."""
return self._get_text_of_elements(self.SIDE_NAVBAR_LOCATORS
["all_topics_side_navbar_options"])

def click_on_a_topic_filter(self, option: str):
"""Click on a topic filter in the side-navbar.
Args:
option (str): The topic filter to click on.
"""
self._click(f"//ul[@class='sidebar-nav--list']/li/a[normalize-space(text())='{option}']")

def get_current_product_filter_dropdown_option(self) -> str:
"""Get the text of the selected option in the product filter dropdown."""
option = self._get_text_of_element(self.SIDE_NAVBAR_LOCATORS
["filter_by_product_dropdown_selected_option"])
return re.sub(r'\s+', ' ', option).strip()

def _get_all_filter_by_product_options(self) -> list[str]:
return super()._get_text_of_elements(self.__filter_by_product_dropdown_options)
def get_all_filter_by_product_options(self) -> list[str]:
"""Get the text of all options in the product filter dropdown."""
return self._get_text_of_elements(self.SIDE_NAVBAR_LOCATORS
["filter_by_product_dropdown_options"])

def select_a_filter_by_product_option(self, option: str):
"""Select a filter by product option in the dropdown.
def _select_a_filter_by_product_option(self, option: str):
super()._select_option_by_label(self.__filter_by_product_dropdown, option)
Args:
option (str): The option to select in the dropdown
"""
self._select_option_by_label(self.SIDE_NAVBAR_LOCATORS
["filter_by_product_dropdown"], option)

def _get_text_of_aaq_widget(self) -> str:
return super()._get_text_of_element(self.__AAQ_widget_text)
def get_text_of_aaq_widget(self) -> str:
"""Get the text of the AAQ widget."""
return self._get_text_of_element(self.SIDE_NAVBAR_LOCATORS["AAQ_widget_text"])

def _click_on_aaq_continue_button(self):
super()._click(self.__AAQ_widget_continue_button)
def click_on_aaq_continue_button(self):
"""Click on the continue button of the AAQ widget."""
self._click(self.SIDE_NAVBAR_LOCATORS["AAQ_widget_continue_button"])

def _is_aaq_text_visible(self) -> bool:
return super()._is_element_visible(self.__AAQ_widget_text)
def is_aaq_text_visible(self) -> bool:
"""Check if the AAQ widget text is visible."""
return self._is_element_visible(self.SIDE_NAVBAR_LOCATORS["AAQ_widget_text"])
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,29 @@
def test_explore_by_topic_product_filter(page: Page):
sumo_pages = SumoPages(page)
utilities = Utilities(page)

with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)
for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
for topic in sumo_pages.explore_by_topic_page.get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
sumo_pages.explore_by_topic_page.click_on_a_topic_filter(topic)
with allure.step("Verifying that the correct page header is displayed"):
assert topic == (sumo_pages.explore_by_topic_page
._get_explore_by_topic_page_header().strip())
for product in sumo_pages.explore_by_topic_page._get_all_filter_by_product_options():
.get_explore_by_topic_page_header().strip())
for product in sumo_pages.explore_by_topic_page.get_all_filter_by_product_options():
product = product.strip()
if product.strip() == "All Products":
continue
else:
sumo_pages.explore_by_topic_page._select_a_filter_by_product_option(
sumo_pages.explore_by_topic_page.select_a_filter_by_product_option(
product.strip())
time.sleep(2)
if not sumo_pages.explore_by_topic_page._get_metadata_of_all_listed_articles():
if not sumo_pages.explore_by_topic_page.get_metadata_of_all_listed_articles():
pytest.fail(f"There is no sublist for {product}")

for sublist in (sumo_pages.explore_by_topic_page
._get_metadata_of_all_listed_articles()):
.get_metadata_of_all_listed_articles()):
assert product in sublist


Expand All @@ -57,29 +58,29 @@ def test_explore_by_topic_aaq_widget_text(page: Page):

with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)
for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
for topic in sumo_pages.explore_by_topic_page.get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page._get_all_filter_by_product_options():
sumo_pages.explore_by_topic_page.click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page.get_all_filter_by_product_options():
product = product.strip()
sumo_pages.explore_by_topic_page._select_a_filter_by_product_option(product)
sumo_pages.explore_by_topic_page.select_a_filter_by_product_option(product)
time.sleep(2)
with allure.step("Verifying the correct AAQ widget text is displayed for products"):
if product == "All Products":
assert (sumo_pages.explore_by_topic_page
._get_text_of_aaq_widget() == AAQWidgetMessages
.get_text_of_aaq_widget() == AAQWidgetMessages
.NEUTRAL_AAQ_SUBHEADING_TEXT)
elif product in utilities.general_test_data['freemium_products']:
assert (sumo_pages.explore_by_topic_page
._get_text_of_aaq_widget() == AAQWidgetMessages
.get_text_of_aaq_widget() == AAQWidgetMessages
.FREEMIUM_AAQ_SUBHEADING_TEXT)
elif product in utilities.general_test_data['premium_products']:
assert (sumo_pages.explore_by_topic_page
._get_text_of_aaq_widget() == AAQWidgetMessages
.get_text_of_aaq_widget() == AAQWidgetMessages
.PREMIUM_AAQ_SUBHEADING_TEXT)
else:
assert not sumo_pages.explore_by_topic_page._is_aaq_text_visible()
assert not sumo_pages.explore_by_topic_page.is_aaq_text_visible()


# C2663960
Expand All @@ -96,18 +97,18 @@ def test_explore_by_topic_aaq_widget_redirect(page: Page):
with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)

for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
for topic in sumo_pages.explore_by_topic_page.get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page._get_all_filter_by_product_options():
sumo_pages.explore_by_topic_page.click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page.get_all_filter_by_product_options():
product = product.strip()
current_url = utilities.get_page_url()
sumo_pages.explore_by_topic_page._select_a_filter_by_product_option(product)
sumo_pages.explore_by_topic_page.select_a_filter_by_product_option(product)
print(f"This is the product: {product}")
time.sleep(2)
with page.expect_navigation() as navigation_info:
sumo_pages.explore_by_topic_page._click_on_aaq_continue_button()
sumo_pages.explore_by_topic_page.click_on_aaq_continue_button()
response = navigation_info.value
assert response.status == 200
if product == "All Products":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ def test_explore_by_topic_redirects(page: Page):
sumo_pages.top_navbar._click(option)

assert (current_option == sumo_pages.explore_by_topic_page
._get_explore_by_topic_page_header())
.get_explore_by_topic_page_header())

with allure.step("Verifying that the correct option is selected inside the 'All "
"Topics' side navbar"):
assert (current_option == sumo_pages.explore_by_topic_page
._get_selected_topic_side_navbar_option())
.get_selected_topic_side_navbar_option())

with allure.step("Verifying that the 'All Products' option is displayed inside the "
"'Filter by product' dropdown"):
assert (sumo_pages.explore_by_topic_page
._get_current_product_filter_dropdown_option()) == 'All Products'
.get_current_product_filter_dropdown_option()) == 'All Products'


# C2462868
Expand Down

0 comments on commit 8e76a2e

Please sign in to comment.