Skip to content

Commit

Permalink
Merge pull request #5901 from emilghittasv/recent-revisions-playwrigh…
Browse files Browse the repository at this point in the history
…t-coverage

Expanding playwright over the following kb sections: show history (coverage increase), article revision page, contributors, recent revisions dashboard
  • Loading branch information
emilghittasv authored Feb 26, 2024
2 parents 6902eeb + 64a86d9 commit 2ca7861
Show file tree
Hide file tree
Showing 27 changed files with 2,400 additions and 168 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ jobs:
if: success() || failure() && steps.create-sessions.outcome == 'success' && steps.kb-threads-setup.outcome == 'success'
run: |
poetry run pytest -m afterThreadTests --numprocesses 1 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_kb_article_threads_tear_down.html --capture=tee-sys
- name: Run KB article show history Tests (${{ env.BROWSER }})
working-directory: playwright_tests
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m kbArticleShowHistory --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_kb_article_show_history.html --capture=tee-sys
- name: Run KB article revisions dashboard Tests (${{ env.BROWSER }})
working-directory: playwright_tests
if: success() || failure() && steps.create-sessions.outcome == 'success'
run: |
poetry run pytest -m recentRevisionsDashboard --numprocesses 2 --browser ${{ env.BROWSER }} --reruns 1 --html=reports/${{ env.BROWSER }}_kb_article_recent_revisions.html --capture=tee-sys
- name: Combine Reports
working-directory: playwright_tests
if: success() || failure()
Expand Down
4 changes: 4 additions & 0 deletions playwright_tests/core/basepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def _get_element_input_value(self, xpath: str) -> str:
def _get_element_inner_text_from_page(self, xpath: str) -> str:
return self._page.inner_text(xpath)

# Get Element text content.
def _get_element_text_content(self, xpath: str) -> str:
return self._page.text_content(xpath)

# Clicking on a particular element.
def _click(self, xpath: str):
self._get_element_locator(xpath).click()
Expand Down
26 changes: 23 additions & 3 deletions playwright_tests/core/testutilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import json
import random
import os
from datetime import datetime

from playwright_tests.messages.homepage_messages import HomepageMessages
from requests.exceptions import HTTPError


@pytest.mark.usefixtures("setup")
class TestUtilities:

# Fetching test data from json files.
with open("test_data/profile_edit.json", "r") as edit_test_data_file:
profile_edit_test_data = json.load(edit_test_data_file)
Expand Down Expand Up @@ -44,6 +44,10 @@ class TestUtilities:
general_test_data = json.load(general_test_data_file)
general_test_data_file.close()

with open("test_data/different_endpoints.json", "r") as different_endpoints_file:
different_endpoints = json.load(different_endpoints_file)
different_endpoints_file.close()

# Fetching user secrets from GH.
user_secrets_accounts = {
"TEST_ACCOUNT_12": os.environ.get("TEST_ACCOUNT_12"),
Expand Down Expand Up @@ -158,19 +162,27 @@ def store_session_cookies(self, session_file_name: str):
self.context.storage_state(path=f"core/sessions/.auth/{session_file_name}.json")

# Deleting page cookies.
def delete_cookies(self):
def delete_cookies(self, tried_once=False):
self.context.clear_cookies()
# Reloading the page for the deletion to take immediate action.
self.refresh_page()

if not self.sumo_pages.top_navbar.is_sign_in_up_button_displayed and not tried_once:
self.delete_cookies(tried_once=True)

# Starting an existing session by applying session cookies.
def start_existing_session(self, session_file_name: str) -> str:
def start_existing_session(self, session_file_name: str, tried_once=False) -> str:
if not tried_once:
self.delete_cookies()
with open(f"core/sessions/.auth/{session_file_name}.json", 'r') as file:
cookies_data = json.load(file)
self.context.add_cookies(cookies=cookies_data['cookies'])
# A SUMO action needs to be done in order to have the page refreshed with the correct
# session
self.refresh_page()

if self.sumo_pages.top_navbar.is_sign_in_up_button_displayed() and not tried_once:
self.start_existing_session(session_file_name, tried_once=True)
return session_file_name

def refresh_page(self):
Expand All @@ -197,3 +209,11 @@ def is_descending(self, list_of_items: list[str]):
return True
else:
return False

def extract_month_day_year_from_string(self, timestamp_str: str) -> str:
timestamp = datetime.strptime(timestamp_str, "%b %d, %Y, %I:%M:%S %p")
return timestamp.strftime("%b %d, %Y")

def extract_date_to_digit_format(self, date_str: str) -> int:
date = datetime.strptime(date_str, "%b %d, %Y")
return int(date.strftime("%m%d%Y"))
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add__valid_data_to_all_input_fields_without_submitting(self,
body_text: str,
os='',
attach_image=False):
aaq_subject = subject + super().generate_random_number(min_value=0, max_value=1000)
aaq_subject = subject + super().generate_random_number(min_value=0, max_value=5000)
# 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
Expand Up @@ -15,20 +15,25 @@ def __init__(self, page: Page):
def submit_simple_kb_article(self,
article_title=None,
article_slug=None,
article_category=None,
allow_discussion=True,
selected_relevancy=True,
selected_topics=True,
search_summary=None,
article_content=None,
submit_article=True) -> dict[str, Any]:
submit_article=True,
is_template=False) -> 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))

if is_template:
kb_article_title = (kb_article_test_data["kb_template_title"] + self.
generate_random_number(0, 5000))
else:
kb_article_title = (kb_article_test_data["kb_article_title"] + self.
generate_random_number(0, 5000))
else:
kb_article_title = article_title

Expand All @@ -41,7 +46,10 @@ def submit_simple_kb_article(self,
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 article_category is None:
super()._select_category_option_by_text(kb_article_test_data["category_options"])
else:
super()._select_category_option_by_text(article_category)

if selected_relevancy is True:
super()._click_on_a_relevant_to_option_checkbox(
Expand Down Expand Up @@ -106,5 +114,6 @@ def submit_simple_kb_article(self,
"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"]
"search_results_summary": kb_article_test_data["search_result_summary"],
"expiry_date": kb_article_test_data["expiry_date"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from playwright_tests.core.testutilities import TestUtilities
from playwright.sync_api import Page
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
from playwright_tests.pages.explore_help_articles.articles.kb_article_show_history_page import \
KBArticleShowHistoryPage
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_page import (
EditKBArticlePage)


class AddKBArticleRevision(TestUtilities,
KBArticlePage,
EditKBArticlePage,
KBArticleShowHistoryPage):
def __init__(self, page: Page):
super().__init__(page)

def submit_new_kb_revision(self,
keywords=None,
search_result_summary=None,
content=None,
expiry_date=None,
changes_description=None,
is_admin=False
) -> str:

super()._click_on_edit_article_option()

# Only admin accounts can update article keywords.
if is_admin:
# Keywords step.
if keywords is None:
super()._fill_edit_article_keywords_field(
self.kb_article_test_data['updated_keywords']
)
else:
super()._fill_edit_article_keywords_field(keywords)

# Search Result Summary step.
if search_result_summary is None:
super()._fill_edit_article_search_result_summary_field(
self.kb_article_test_data['updated_search_result_summary']
)
else:
super()._fill_edit_article_search_result_summary_field(search_result_summary)

# Content step.
if content is None:
super()._fill_edit_article_content_field(
self.kb_article_test_data['updated_article_content']
)
else:
super()._fill_edit_article_content_field(content)

# Expiry date step.
if expiry_date is None:
super()._fill_edit_article_expiry_date(
self.kb_article_test_data['updated_expiry_date']
)
else:
super()._fill_edit_article_expiry_date(expiry_date)

# Submitting for preview steps
super()._click_submit_for_review_button()

if changes_description is None:
super()._fill_edit_article_changes_panel_comment(
self.kb_article_test_data['changes_description']
)
else:
super()._fill_edit_article_changes_panel_comment(changes_description)

super()._click_edit_article_changes_panel_submit_button()

return super()._get_last_revision_id()
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def __init__(self, page: Page):
def add_new_kb_discussion_thread(self, title='') -> dict[str, Any]:
if title == '':
thread_title = (super().kb_new_thread_test_data['new_thread_title'] + super()
.generate_random_number(0, 1000))
.generate_random_number(0, 5000))
else:
thread_title = (title + super()
.generate_random_number(0, 1000))
.generate_random_number(0, 5000))
thread_body = super().kb_new_thread_test_data['new_thread_body']

# Adding text to the title field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ class KBArticleRevision:
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:"
KB_ARTICLE_REVISION_NO_STATUS = "No"
KB_ARTICLE_REVISION_YES_STATUS = "Yes"
KB_REVISION_CANNOT_DELETE_ONLY_REVISION_HEADER = ("Unable to delete only revision of the "
"document")
KB_REVISION_CANNOT_DELETE_ONLY_REVISION_SUBHEADER = ("To delete the document, please notify "
"an admin.")
KB_REVISION_PREVIEW = "/revision/"

def get_kb_article_revision_details(self,
revision_id: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class KBArticleShowHistoryPageMessages:
PAGE_TITLE = "History of "
DEFAULT_REVISION_FOR_LOCALE = "English"

def get_delete_revision_endpoint(self, article_slug: str, revision_id: int) -> str:
return f"https://support.allizom.org/en-US/kb/{article_slug}/revision/{revision_id}/delete"

def get_remove_contributor_page_header(self, expected_username: str) -> str:
return (f"Are you sure you want to remove {expected_username} from the document "
f"contributors?")

def get_contributor_added_message(self, expected_username: str) -> str:
return f"{expected_username} added to the contributors successfully!"

def get_contributor_removed_message(self, expected_username: str) -> str:
return f"{expected_username} removed from the contributors successfully!"
Loading

0 comments on commit 2ca7861

Please sign in to comment.