Skip to content

Commit

Permalink
Merge pull request #6405 from emilghittasv/playwright-coverage-expansion
Browse files Browse the repository at this point in the history
Playwright expand searchbar coverage on different pages
  • Loading branch information
emilghittasv authored Dec 11, 2024
2 parents 7303cd6 + 240b91e commit f89c73d
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 53 deletions.
52 changes: 43 additions & 9 deletions playwright_tests/pages/search/search_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
class SearchPage(BasePage):
# Locators belonging to the searchbar.
SEARCHBAR_LOCATORS = {
"searchbar": "//form[@id='support-search-masthead']/input[@id='search-q']",
"searchbar_homepage": "//form[@id='support-search-masthead']/input[@id='search-q']",
"searchbar_aaq": "//form[@id='question-search-masthead']/input[@id='search-q']",
"searchbar_sidebar": "//form[@id='support-search-sidebar']/input[@id='search-q']",
"hidden_searchbar": "//form[@id='hidden-search']/input[@id='search-q']",
"searchbar_search_button": "//form[@id='support-search-masthead']/button",
"search_results_header": "//div[@class='home-search-section--content']/h2",
"popular_searches": "//p[@class='popular-searches']/a"
"popular_searches": "//p[@class='popular-searches']/a",
"search_results_section": "//main[@id='search-results-list']"
}

# Locators belonging to the search results filter
Expand Down Expand Up @@ -41,6 +45,9 @@ class SearchPage(BasePage):
def __init__(self, page: Page):
super().__init__(page)

def _wait_for_visibility_of_search_results_section(self):
self._wait_for_selector(self.SEARCHBAR_LOCATORS["search_results_section"])

"""
Actions against the search results
"""
Expand All @@ -58,6 +65,7 @@ def get_search_result_summary_text_of_a_particular_article(self, article_title)
Args:
article_title (str): The title of the article
"""
self._wait_for_visibility_of_search_results_section()
return self._get_text_of_element(f"//h3[@class='sumo-card-heading']/"
f"a[normalize-space(text())='{article_title}']/../"
f"../p")
Expand All @@ -68,6 +76,7 @@ def is_a_particular_article_visible(self, article_title: str) -> bool:
Args:
article_title (str): The title of the article
"""
self._wait_for_visibility_of_search_results_section()
return self._is_element_visible(f"//h3[@class='sumo-card-heading']/"
f"a[normalize-space(text())='{article_title}']")

Expand All @@ -77,11 +86,13 @@ def click_on_a_particular_article(self, article_title: str):
Args:
article_title (str): The title of the article
"""
self._wait_for_visibility_of_search_results_section()
self._click(f"//h3[@class='sumo-card-heading']/"
f"a[normalize-space(text())='{article_title}']")

def get_all_bolded_content(self) -> list[str]:
"""Get all the bolded content of the search results"""
self._wait_for_visibility_of_search_results_section()
return self._get_text_of_elements(self.SEARCH_RESULTS_LOCATORS
["all_bolded_article_content"])

Expand All @@ -91,6 +102,7 @@ def get_all_search_results_article_bolded_content(self, article_title: str) -> l
Args:
article_title (str): The title of the article
"""
self._wait_for_visibility_of_search_results_section()
if "'" in article_title:
parts = article_title.split("'")
if len(parts) > 1:
Expand All @@ -110,10 +122,12 @@ def get_all_search_results_article_bolded_content(self, article_title: str) -> l

def get_all_search_results_article_titles(self) -> list[str]:
"""Get all the titles of the search results"""
self._wait_for_visibility_of_search_results_section()
return self._get_text_of_elements(self.SEARCH_RESULTS_LOCATORS["search_results_titles"])

def get_all_search_results_articles_summary(self) -> list[str]:
"""Get all the summaries of the search results"""
self._wait_for_visibility_of_search_results_section()
return self._get_text_of_elements(self.SEARCH_RESULTS_LOCATORS
["search_results_articles_summary"])

Expand All @@ -123,6 +137,7 @@ def get_locator_of_a_particular_article(self, article_title: str) -> Locator:
Args:
article_title (str): The title of the article
"""
self._wait_for_visibility_of_search_results_section()
return self._get_element_locator(f"//h3[@class='sumo-card-heading']/"
f"a[normalize-space(text())='{article_title}']")

Expand All @@ -136,20 +151,38 @@ def is_search_content_section_displayed(self) -> bool:

def get_text_of_searchbar_field(self) -> str:
"""Get the text of the search bar field"""
return self._get_element_input_value(self.SEARCHBAR_LOCATORS["searchbar"])
return self._get_element_input_value(self.SEARCHBAR_LOCATORS["searchbar_homepage"])

def fill_into_searchbar(self, text: str):
def fill_into_searchbar(self, text: str, is_aaq=False, is_sidebar=False):
"""Fill into the search bar
Args:
text (str): The text to fill into the search bar
is_aaq (bool): Whether the search bar is on the AAQ flow pages
is_sidebar (bool): Whether the search bar is on the sidebar
"""
self.clear_the_searchbar()
self._fill(self.SEARCHBAR_LOCATORS["searchbar"], text)
if is_aaq:
self.clear_the_searchbar(is_aaq=True)
self._fill(self.SEARCHBAR_LOCATORS["searchbar_aaq"], text)
elif is_sidebar:
self._fill(self.SEARCHBAR_LOCATORS["searchbar_sidebar"], text)
else:
self.clear_the_searchbar()
self._fill(self.SEARCHBAR_LOCATORS["searchbar_homepage"], text)

def clear_the_searchbar(self, is_aaq=False, is_sidebar=False):
"""Clear the search bar
def clear_the_searchbar(self):
"""Clear the search bar"""
self._clear_field(self.SEARCHBAR_LOCATORS["searchbar"])
Args:
is_aaq (bool): Whether the search bar is on the AAQ flow pages
is_sidebar (bool): Whether the search bar is on the sidebar
"""
if is_aaq:
self._clear_field(self.SEARCHBAR_LOCATORS["searchbar_aaq"])
elif is_sidebar:
self._clear_field(self.SEARCHBAR_LOCATORS["hidden_searchbar"])
else:
self._clear_field(self.SEARCHBAR_LOCATORS["searchbar_homepage"])

def click_on_search_button(self):
"""Click on the search button"""
Expand Down Expand Up @@ -188,4 +221,5 @@ def click_on_a_particular_side_nav_item(self, product_name: str):
"""
def get_search_results_header(self) -> str:
"""Get the search results header"""
self._wait_for_visibility_of_search_results_section()
return self._get_text_of_element(self.SEARCHBAR_LOCATORS["search_results_header"])
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pytest_check import check
from playwright_tests.core.utilities import Utilities
from playwright.sync_api import expect, TimeoutError, Page

from playwright_tests.messages.contribute_messages.con_tools.moderate_forum_messages import (
ModerateForumContentPageMessages)
from playwright_tests.messages.ask_a_question_messages.AAQ_messages.question_page_messages import (
Expand All @@ -19,7 +18,6 @@


# C2191086, C2191094, C2191263, C2191263, C2191087, C2191088
# T5696747, T5696755, T5696748, T5696751, T5696749
@pytest.mark.postedQuestions
@pytest.mark.parametrize("username", ['TEST_ACCOUNT_MESSAGE_5', ''])
def test_posted_question_details(page: Page, username):
Expand Down Expand Up @@ -64,7 +62,7 @@ def test_posted_question_details(page: Page, username):
sumo_pages.aaq_flow.deleting_question_flow()


# T5696750, T5696753
# T5696750, T5696753, C2103331
@pytest.mark.postedQuestions
def test_edit_this_question_functionality_not_signed_in(page: Page):
utilities = Utilities(page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from playwright_tests.pages.sumo_pages import SumoPages


# C890370, C890374
# C890370, C890374, C890372
@pytest.mark.productSolutionsPage
def test_featured_articles_redirect(page: Page, is_chromium):
if is_chromium:
Expand Down
Loading

0 comments on commit f89c73d

Please sign in to comment.