Skip to content

Commit

Permalink
Merge pull request #6278 from emilghittasv/playwright-search-tests
Browse files Browse the repository at this point in the history
Playwright adding the first batch of search tests
  • Loading branch information
emilghittasv authored Oct 10, 2024
2 parents 4cc50d8 + 0824881 commit 76eaef1
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 45 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ on:
- recentRevisionsDashboard
- kbDashboard
- exploreByTopics
- searchTests

env:
TEST_ACCOUNT_12: ${{secrets.AUTOMATION_TEST_ACCOUNT_12}}
Expand Down Expand Up @@ -71,6 +72,9 @@ jobs:
sudo apt-get update
pip3 install --user poetry
poetry install
- name: Download NLTK Data
run: |
poetry run python -m nltk.downloader wordnet omw-1.4
- name: Ensure Playwright browsers are installed
run: |
pip3 install playwright
Expand Down Expand Up @@ -98,7 +102,7 @@ jobs:
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
declare dispatch_test_suite="${{inputs.TestSuite}}"
declare all_test_suites=("homePageTests" "topNavbarTests" "footerSectionTests" "contributePagesTests" "messagingSystem" "messagingSystemCleanup" "userContributionTests" "userProfile" "userSettings" "editUserProfileTests" "userQuestions" "contactSupportPage" "productSolutionsPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics")
declare all_test_suites=("homePageTests" "topNavbarTests" "footerSectionTests" "contributePagesTests" "messagingSystem" "messagingSystemCleanup" "userContributionTests" "userProfile" "userSettings" "editUserProfileTests" "userQuestions" "contactSupportPage" "productSolutionsPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics", "searchTests")
if [ "$dispatch_test_suite" == "All" ] || [ "${{ github.event_name}}" == "schedule" ] ; then
for test in "${all_test_suites[@]}"; do
if ! poetry run pytest -m ${test} --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1; then
Expand Down
18 changes: 10 additions & 8 deletions playwright_tests/core/utilities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from typing import Any, Union

import os
import requests
import time
import re
import json
import random
import os
from typing import Any, Union
from datetime import datetime

from nltk import SnowballStemmer
from nltk import SnowballStemmer, WordNetLemmatizer
from playwright.sync_api import Page
from playwright_tests.messages.homepage_messages import HomepageMessages
from requests.exceptions import HTTPError
Expand Down Expand Up @@ -384,15 +382,19 @@ def _contains_synonym(self, search_result_lower, search_term: Union[str, list[st
(split term) are present in the search result.
"""
synonyms = None
lemmenizer = WordNetLemmatizer()

if isinstance(search_term, list):
for term in search_term:
synonyms = SearchSynonyms.synonym_dict.get(term.lower(), [])
synonyms = SearchSynonyms.synonym_dict.get(lemmenizer.lemmatize(term.lower(),
pos='n'), [])
else:
synonyms = SearchSynonyms.synonym_dict.get(search_term.lower(), [])
synonyms = SearchSynonyms.synonym_dict.get(lemmenizer.lemmatize(search_term.lower(),
pos='n'), [])

for term in search_term_split:
synonyms.extend(SearchSynonyms.synonym_dict.get(term, []))
synonyms.extend(SearchSynonyms.synonym_dict.get(lemmenizer.lemmatize(term, pos='n'),
[]))

for synonym in synonyms:
if synonym.lower() in search_result_lower:
Expand Down
12 changes: 6 additions & 6 deletions playwright_tests/pages/footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def __init__(self, page: Page):
super().__init__(page)

# Footer section actions.
def _get_all_footer_links(self) -> list[ElementHandle]:
return super()._get_element_handles(self.__all_footer_links)
def get_all_footer_links(self) -> list[ElementHandle]:
return self._get_element_handles(self.__all_footer_links)

def _get_all_footer_locales(self) -> list[str]:
return super()._get_element_attribute_value(super()._get_elements_locators(
def get_all_footer_locales(self) -> list[str]:
return self._get_element_attribute_value(self._get_elements_locators(
self.__language_selector_options), "value")

def _switch_to_a_locale(self, locale: str):
super()._select_option_by_value(self.__language_selector, locale)
def switch_to_a_locale(self, locale: str):
self._select_option_by_value(self.__language_selector, locale)
35 changes: 19 additions & 16 deletions playwright_tests/pages/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,31 @@ def __init__(self, page: Page):
super().__init__(page)

# Product Cards
def _get_text_of_product_card_titles(self) -> list[str]:
return super()._get_text_of_elements(self.__product_card_titles)
def get_text_of_product_card_titles(self) -> list[str]:
return self._get_text_of_elements(self.__product_card_titles)

def _click_on_product_card(self, element_number):
super()._click_on_an_element_by_index(self.__product_list, element_number)
def click_on_product_card(self, element_number):
self._click_on_an_element_by_index(self.__product_list, element_number)

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

# Featured articles
def _get_number_of_featured_articles(self) -> int:
return super()._get_elements_count(self.__featured_articles_list)
def get_number_of_featured_articles(self) -> int:
return self._get_elements_count(self.__featured_articles_list)

def _get_featured_articles_titles(self) -> list[str]:
return super()._get_text_of_elements(self.__featured_articles_card_titles)
def get_featured_articles_titles(self) -> list[str]:
return self._get_text_of_elements(self.__featured_articles_card_titles)

def _click_on_a_featured_card(self, element_number: int):
super()._click_on_an_element_by_index(self.__featured_articles_card_items, element_number)
def click_on_a_featured_card(self, element_number: int):
self._click_on_an_element_by_index(self.__featured_articles_card_items, element_number)

# Learn More
def _click_learn_more_option(self):
super()._click(self.__learn_more_option)
def click_learn_more_option(self):
self._click(self.__learn_more_option)

def _get_community_card_title(self) -> str:
return super()._get_text_of_element(self.__join_our_community_card_title)
def get_community_card_title(self) -> str:
return self._get_text_of_element(self.__join_our_community_card_title)

def _get_community_card_description(self) -> str:
return super()._get_text_of_element(self.__join_our_community_card_description)
def get_community_card_description(self) -> str:
return self._get_text_of_element(self.__join_our_community_card_description)
1 change: 1 addition & 0 deletions playwright_tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ markers =
deleteAllRestrictedTestArticles: Deleting all restricted test articles.
create_delete_article: Fixture used for creating and deleting test articles.
exploreByTopics: Tests belonging to the explore help articles by topics page.
searchTests: Tests belonging to the search functionality.
addopts = --alluredir=./reports/allure_reports --tb=no
4 changes: 2 additions & 2 deletions playwright_tests/test_data/search_synonym.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class SearchSynonyms:
'addon': ['extension', 'theme'],
'add-on': ['extension', 'theme'],
'add-ons': ['extensions', 'themes', "addon"],
'extension': ['addon', 'theme'],
'theme': ['addon', 'extension'],
'extension': ['addon', 'theme', 'add-on'],
'theme': ['addon', 'extension', 'add-on'],
'awesome bar': ['address bar', 'url bar', 'location bar', 'location field', 'url field'],
'address bar': ['awesome bar', 'url bar', 'location bar', 'location field', 'url field'],
'url bar': ['awesome bar', 'address bar', 'location bar', 'location field', 'url field'],
Expand Down
6 changes: 3 additions & 3 deletions playwright_tests/tests/footer_tests/test_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@pytest.mark.footerSectionTests
def test_all_footer_links_are_working(page: Page):
sumo_pages = SumoPages(page)
for link in sumo_pages.footer_section._get_all_footer_links():
for link in sumo_pages.footer_section.get_all_footer_links():
relative_url = link.get_attribute("href")

# Verify if URL is absolute, and construct the full URL if it's not
Expand Down Expand Up @@ -48,8 +48,8 @@ def test_locale_selector(page: Page):
sumo_pages = SumoPages(page)
with allure.step("Verifying that all footer select options are redirecting the user to the "
"correct page locale"):
for locale in sumo_pages.footer_section._get_all_footer_locales():
sumo_pages.footer_section._switch_to_a_locale(locale)
for locale in sumo_pages.footer_section.get_all_footer_locales():
sumo_pages.footer_section.switch_to_a_locale(locale)
expect(
page
).to_have_url(re.compile(f".*{locale}"))
18 changes: 9 additions & 9 deletions playwright_tests/tests/homepage_tests/test_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_join_our_community_card_learn_more_redirects_to_contribute_page(page: P
sumo_pages = SumoPages(page)
utilities = Utilities(page)
with allure.step("Clicking on the 'Learn More' option"):
sumo_pages.homepage._click_learn_more_option()
sumo_pages.homepage.click_learn_more_option()

with allure.step("Verifying that we are redirected to the 'Contribute' page successfully"):
assert (
Expand All @@ -34,9 +34,9 @@ def test_join_our_community_card_has_the_correct_content(page: Page):
"Verifying that the 'Join Our Community' card has the correct strings applied"
):
assert (
sumo_pages.homepage._get_community_card_title()
sumo_pages.homepage.get_community_card_title()
== HomepageMessages.JOIN_OUR_COMMUNITY_CARD_TITLE
and sumo_pages.homepage._get_community_card_description()
and sumo_pages.homepage.get_community_card_description()
== HomepageMessages.JOIN_OUR_COMMUNITY_CARD_DESCRIPTION
), "Incorrect strings are displayed"

Expand All @@ -49,15 +49,15 @@ def test_homepage_feature_articles_are_available_and_interactable(page: Page):
with check, allure.step(
"Verifying if the correct number of featured articles are present on the homepage"
):
assert sumo_pages.homepage._get_number_of_featured_articles(
assert sumo_pages.homepage.get_number_of_featured_articles(
) is HomepageMessages.EXPECTED_FEATURED_ARTICLES_COUNT

with allure.step("Clicking on each featured article card and verifying that the user is"
"redirected to the correct article page."):
counter = 0
for featured_article in sumo_pages.homepage._get_featured_articles_titles():
articles_names = sumo_pages.homepage._get_featured_articles_titles()
sumo_pages.homepage._click_on_a_featured_card(counter)
for featured_article in sumo_pages.homepage.get_featured_articles_titles():
articles_names = sumo_pages.homepage.get_featured_articles_titles()
sumo_pages.homepage.click_on_a_featured_card(counter)
assert (
sumo_pages.kb_article_page.get_text_of_article_title().strip()
== articles_names[counter].strip()
Expand All @@ -75,11 +75,11 @@ def test_product_cards_are_functional_and_redirect_to_the_proper_support_page(pa
sumo_pages = SumoPages(page)
utilities = Utilities(page)
with allure.step("Verifying that the product cards redirect to the correct support page"):
card_titles = sumo_pages.homepage._get_text_of_product_card_titles()
card_titles = sumo_pages.homepage.get_text_of_product_card_titles()
counter = 0
for product_card in card_titles:
expected_product_title = card_titles[counter] + SupportPageMessages.TITLE_CONTAINS
sumo_pages.homepage._click_on_product_card(counter)
sumo_pages.homepage.click_on_product_card(counter)
assert (
expected_product_title
== sumo_pages.product_support_page._get_product_support_title_text()
Expand Down
Loading

0 comments on commit 76eaef1

Please sign in to comment.