Skip to content

Commit

Permalink
Merge pull request #5859 from emilghittasv/expanding-playwright-kb-co…
Browse files Browse the repository at this point in the history
…verage

Expanding playwright coverage over KB
  • Loading branch information
emilghittasv authored Jan 25, 2024
2 parents ded6eb0 + 5be1e80 commit c9e07b1
Show file tree
Hide file tree
Showing 71 changed files with 2,025 additions and 259 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ jobs:
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m postedQuestions --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_aaq_questions_tests.html --capture=tee-sys
- name : Run KB Products Page Tests (${{ env.BROWSER }})
working-directory: playwright_tests
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m kbProductsPage --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_kb_products_page.html --capture=tee-sys
- name: Run Product Support Page Tests (${{ env.BROWSER }})
working-directory: playwright_tests
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m productSupportPage --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_product_support_page.html --capture=tee-sys
- name: Run KB Article Creation And Access Tests (${{ env.BROWSER }})
working-directory: playwright_tests
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m kbArticleCreationAndAccess --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_kb_article_creation_and_access.html --capture=tee-sys
- name: Combine Reports
working-directory: playwright_tests
if: success() || failure()
Expand Down
2 changes: 1 addition & 1 deletion playwright_tests/core/basepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _wait_for_selector(self, xpath: str):
try:
self._page.wait_for_selector(xpath, timeout=3500)
except TimeoutError:
print("Use a different account button is not displayed")
print(f"{xpath} is not displayed")

# Clears the browser session storage and reloads the page after.
def clear_session_storage(self):
Expand Down
15 changes: 13 additions & 2 deletions playwright_tests/core/testutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class TestUtilities:
kb_article_test_data = json.load(kb_article_test_data_file)
kb_article_test_data_file.close()

with open("test_data/kb_new_thread.json", "r") as kb_new_thread_test_data_file:
kb_new_thread_test_data = json.load(kb_new_thread_test_data_file)
kb_article_test_data_file.close()

with open("test_data/user_message.json", "r") as user_message_test_data_file:
user_message_test_data = json.load(user_message_test_data_file)
user_message_test_data_file.close()
Expand Down Expand Up @@ -88,13 +92,16 @@ def username_extraction_from_email(self, string_to_analyze: str) -> str:
return re.match(r"(.+)@", string_to_analyze).group(1)

# Random number generator.
def generate_random_number(self, min_value, max_value) -> int:
return random.randint(min_value, max_value)
def generate_random_number(self, min_value, max_value) -> str:
return str(random.randint(min_value, max_value))

# Extracting numbers from string.
def number_extraction_from_string(self, string_to_analyze: str) -> int:
return int(re.findall(r"\d+", string_to_analyze)[0])

def number_extraction_from_string_endpoint(self, endpoint: str, string_to_analyze: str) -> int:
return int(re.findall(fr'{endpoint}(\d+)', string_to_analyze)[0])

# Defining the logging mechanism.
def get_logger(self):
logger_name = inspect.stack()[1][3]
Expand Down Expand Up @@ -180,3 +187,7 @@ def replace_special_chars_account(self, account: str) -> str:
# Removing a particular character from a given string.
def remove_character_from_string(self, string: str, character_to_remove: str) -> str:
return string.replace(character_to_remove, "")

def create_slug_from_title(self, article_title: str) -> str:
initial_title = article_title.split()
return '-'.join(initial_title).lower()
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from playwright.sync_api import Page
from playwright_tests.core.testutilities import TestUtilities
from playwright_tests.pages.get_help_pages.product_solutions_pages.product_solutions_page import (
from playwright_tests.pages.ask_a_question.product_solutions_pages.product_solutions_page import (
ProductSolutionsPage)
from playwright_tests.pages.top_navbar import TopNavbar
from playwright_tests.pages.get_help_pages.aaq_pages.aaq_form_page import AAQFormPage
from playwright_tests.pages.user_questions_pages.questions_page import QuestionPage
from playwright_tests.pages.ask_a_question.aaq_pages.aaq_form_page import AAQFormPage
from playwright_tests.pages.ask_a_question.posted_question_pages.questions_page import QuestionPage


class AAQFlow(AAQFormPage, ProductSolutionsPage, TopNavbar, TestUtilities, QuestionPage):
Expand Down Expand Up @@ -44,8 +44,7 @@ def add__valid_data_to_all_input_fields_without_submitting(self,
body_text: str,
os='',
attach_image=False):
random_number = str(super().generate_random_number(min_value=0, max_value=1000))
aaq_subject = subject + random_number
aaq_subject = subject + super().generate_random_number(min_value=0, max_value=1000)
# Adding text to subject field.
super()._add_text_to_aaq_form_subject_field(aaq_subject)
# Selecting a topic.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from playwright.sync_api import Page
from typing import Any
from playwright_tests.core.testutilities import TestUtilities
from playwright_tests.messages.explore_help_articles.kb_article_page_messages import (
KBArticlePageMessages)
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import (
SubmitKBArticlePage)


class AddKbArticleFlow(TestUtilities, SubmitKBArticlePage):

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

def submit_simple_kb_article(self,
article_title=None,
article_slug=None,
allow_discussion=True,
selected_relevancy=True,
selected_topics=True,
search_summary=None,
article_content=None,
submit_article=True) -> dict[str, Any]:
self._page.goto(KBArticlePageMessages.CREATE_NEW_KB_ARTICLE_STAGE_URL)

kb_article_test_data = super().kb_article_test_data

if article_title is None:
kb_article_title = (kb_article_test_data["kb_article_title"] + self.
generate_random_number(0, 1000))

else:
kb_article_title = article_title

if kb_article_title != "":
super()._add_text_to_article_form_title_field(
kb_article_title
)

if (article_slug is not None) and (article_slug != ""):
kb_article_slug = article_slug
super()._add_text_to_article_slug_field(kb_article_slug)

super()._select_category_option_by_text(kb_article_test_data["category_options"])

if selected_relevancy is True:
super()._click_on_a_relevant_to_option_checkbox(
kb_article_test_data["relevant_to_option"]
)

# Adding Article topic
if selected_topics is True:
super()._click_on_a_particular_parent_topic(
kb_article_test_data["selected_parent_topic"]
)
super()._click_on_a_particular_child_topic_checkbox(
kb_article_test_data["selected_parent_topic"],
kb_article_test_data["selected_child_topic"],
)

# Interacting with Allow Discussion checkbox
if (allow_discussion is True) and (super(

)._is_allow_discussion_on_article_checkbox_checked() is False):
super()._check_allow_discussion_on_article_checkbox()
elif (allow_discussion is False) and (super(

)._is_allow_discussion_on_article_checkbox_checked() is True):
super()._check_allow_discussion_on_article_checkbox()

super()._add_text_to_related_documents_field(kb_article_test_data["related_documents"])
super()._add_text_to_keywords_field(kb_article_test_data["keywords"])

if search_summary is None:
super()._add_text_to_search_result_summary_field(
kb_article_test_data["search_result_summary"]
)

if not super()._is_content_textarea_displayed():
super()._click_on_toggle_syntax_highlight_option()

if article_content is None:
super()._add_text_to_content_textarea(kb_article_test_data["article_content"])

super()._add_text_to_expiry_date_field(kb_article_test_data["expiry_date"])
# We need to evaluate in order to fetch the slug field value
slug = self._page.evaluate(
'document.getElementById("id_slug").value'
)

if submit_article is True:
# If title and slug are empty we are not reaching the description field.
if ((article_title != '') and (article_slug != '') and (
search_summary is None) and (article_content is None)):
super()._click_on_submit_for_review_button()
super()._add_text_to_changes_description_field(
kb_article_test_data["changes_description"]
)
super()._click_on_changes_submit_button()
else:
super()._click_on_submit_for_review_button()

return {"article_title": kb_article_title,
"article_content": kb_article_test_data["article_content"],
"article_content_html": kb_article_test_data['article_content_html_rendered'],
"article_slug": slug,
"article_review_description": kb_article_test_data["changes_description"],
"keyword": kb_article_test_data["keywords"],
"search_results_summary": kb_article_test_data["search_result_summary"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import Any
from playwright_tests.core.testutilities import TestUtilities
from playwright_tests.messages.explore_help_articles.kb_article_page_messages import (
KBArticlePageMessages)
from playwright_tests.pages.explore_help_articles.articles.kb_article_discussion_page import (
KBArticleDiscussionPage)
from playwright.sync_api import Page


class PostNewDiscussionThreadFlow(TestUtilities, KBArticleDiscussionPage):
def __init__(self, page: Page):
super().__init__(page)

def add_new_kb_discussion_thread(self) -> dict[str, Any]:
thread_title = (super().kb_new_thread_test_data['new_thread_title'] + super()
.generate_random_number(0, 1000))
thread_body = super().kb_new_thread_test_data['new_thread_body']

# Adding text to the title field.
super()._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)

# Clicking on the post a new thread option.
super()._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(
KBArticlePageMessages.KB_ARTICLE_DISCUSSIONS_ENDPOINT, thread_url)
)

return {
"thread_title": thread_title,
"thread_body": thread_body,
"thread_url": thread_url,
"thread_id": thread_id
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class KBArticlePageMessages:
CREATE_NEW_KB_ARTICLE_STAGE_URL = "https://support.allizom.org/en-US/kb/new"
KB_ARTICLE_PAGE_URL = "https://support.allizom.org/en-US/kb/"
KB_ARTICLE_HISTORY_URL_ENDPOINT = "/history"
KB_ARTICLE_DISCUSSIONS_ENDPOINT = "/discuss/"
GET_COMMUNITY_SUPPORT_ARTICLE_LINK = ("https://support.allizom.org/en-US/kb/get-community"
"-support?exit_aaq=1")
UNREVIEWED_REVISION_STATUS = "Unreviewed"
REVIEW_REVISION_STATUS = "Review"
CURRENT_REVISION_STATUS = "Current"
KB_ARTICLE_NOT_APPROVED_CONTENT = "This article doesn't have approved content yet."
KB_ARTICLE_SUBMISSION_TITLE_ERRORS = ["Document with this Title and Locale already exists.",
"Document with this Slug and Locale already exists."]
KB_ARTICLE_RELEVANCY_ERROR = "Please select at least one product."
KB_ARTICLE_TOPIC_ERROR = "Please select at least one topic."
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class KBArticleRevision:
KB_ARTICLE_REVISION_HEADER = "Review Revision of "
UNREVIEWED_REVISION_HEADER = " Unreviewed Revision: "
KB_ARTICLE_REVISION_NO_CURRENT_REV_TEXT = "This document does not have a current revision."
KB_ARTICLE_REVISION_KEYWORD_HEADER = "Keywords:"

def get_kb_article_revision_details(self,
revision_id: str,
username: str,
revision_comment: str) -> str:
return (f"Reviewing Revision {revision_id} by {username}. Back to HistoryRevision Comment:"
f" {revision_comment}")

def get_unreviewed_revision_details(self,
revision_id: str,
username: str,
revision_comment: str) -> str:
return (f"Revision {revision_id} by {username}. Revision Comment: {revision_comment}Review"
f" Revision {revision_id}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ProductsPageMessages:
PRODUCTS_PAGE_HEADER = "Products"
PRODUCT_CARDS_SUBHEADING = {
"Firefox": "Web browser for Windows, Mac and Linux",
"Firefox for Android": "Web browser for Android smartphones and tablets",
"Firefox for iOS": "Firefox for iPhone, iPad and iPod touch devices",
"Mozilla VPN": "VPN for Windows 10, Mac, Linux, Android, and iOS devices",
"Firefox Relay": "Service that lets you create email masks to hide your real email "
"address",
"Monitor": "Find out if your private information has been exposed in a known data breach.",
"Pocket": "Discover and save stories for later.",
"MDN Plus": "MDN Plus provides a custom user experience for MDN supporters.",
"Hubs": "Collaborate and engage with each other through spatialized audio and with media "
"from around the web.",
"Firefox Focus": "Automatic privacy browser and content blocker",
"Firefox for Enterprise": "Firefox Quantum for businesses",
"Thunderbird": "Email software for Windows, Mac and Linux"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ProductSupportPageMessages:
PRODUCT_SUPPORT_PAGE_TITLE = " Support"
PRODUCT_SUPPORT_PAGE_FREQUENT_TOPICS_TITLE = "Frequent Topics"
PRODUCT_SUPPORT_PAGE_FREQUENT_TOPICS_SUBTITLE = "Explore the knowledge base."
PRODUCT_SUPPORT_PAGE_FREQUENT_ARTICLES_TITLE = "Featured Articles"
STILL_NEED_HELP_WIDGET_TITLE = "Still need help?"
STILL_NEED_HELP_WIDGET_CONTENT_FREEMIUM = ("We’re here for you. Post a question to our "
"support forums and get answers from our "
"community of experts.")
STILL_NEED_HELP_WIDGET_CONTENT_PREMIUM = ("We’re here for you! If you haven’t found a "
"solution after exploring our help articles, "
"you can get in touch with our support team.")
STILL_NEED_HELP_WIDGET_BUTTON_TEXT_FREEMIUM = "Ask the Community"
STILL_NEED_HELP_WIDGET_BUTTON_TEXT_PREMIUM = "Get Support"
JOIN_OUR_COMMUNITY_SECTION_HEADER = "Join Our Community"
JOIN_OUR_COMMUNITY_SECTION_CONTENT = ("Grow and share your expertise with others. Answer "
"questions and improve our knowledge base.")

This file was deleted.

Loading

0 comments on commit c9e07b1

Please sign in to comment.