Skip to content

Commit 107ead7

Browse files
authored
Merge pull request #6726 from emilghittasv/playwright-update-aaq
Playwright: Extend coverage to related documents functionality
2 parents 66a5e76 + ab54c3e commit 107ead7

File tree

7 files changed

+260
-10
lines changed

7 files changed

+260
-10
lines changed

playwright_tests/flows/explore_articles_flows/article_flows/edit_article_meta_flow.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
77
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_meta import (
88
KBArticleEditMetadata)
9+
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_page import \
10+
EditKBArticlePage
911
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import \
1012
SubmitKBArticlePage
1113

@@ -17,6 +19,7 @@ def __init__(self, page: Page):
1719
self.kb_article_edit_metadata_page = KBArticleEditMetadata(page)
1820
self.submit_kb_article_page = SubmitKBArticlePage(page)
1921
self.kb_article_page = KBArticlePage(page)
22+
self.edit_kb_article_page = EditKBArticlePage(page)
2023

2124
def edit_article_metadata(self, **kwargs):
2225
return self.utilities.re_call_function_on_error(
@@ -33,11 +36,15 @@ def _edit_article_metadata(self, title=None,
3336
needs_change=False,
3437
needs_change_comment=False,
3538
restricted_to_groups: list[str] = None,
39+
related_documents: list[str] = None,
3640
single_group=""):
3741

3842
if KBArticleRevision.KB_EDIT_METADATA not in self.utilities.get_page_url():
3943
self.kb_article_page.click_on_edit_article_metadata()
4044

45+
if self.edit_kb_article_page.is_edit_anyway_option_visible():
46+
self.edit_kb_article_page.click_on_edit_anyway_option()
47+
4148
if restricted_to_groups:
4249
for group in restricted_to_groups:
4350
(self.kb_article_edit_metadata_page
@@ -101,17 +108,23 @@ def _edit_article_metadata(self, title=None,
101108
if self.kb_article_edit_metadata_page.is_needs_change_checkbox():
102109
self.kb_article_edit_metadata_page.click_needs_change_checkbox()
103110

111+
if related_documents:
112+
for document in related_documents:
113+
self.kb_article_edit_metadata_page.add_related_documents(document)
114+
104115
self.kb_article_edit_metadata_page.click_on_save_changes_button()
105116

106117
def remove_a_restricted_visibility_group(self, **kwargs):
107118
return self.utilities.re_call_function_on_error(
108119
lambda: self._remove_a_restricted_visibility_group(**kwargs)
109120
)
110121

111-
def _remove_a_restricted_visibility_group(self, group_name=''):
122+
def _remove_a_restricted_visibility_group(self, group_name=""):
112123
if KBArticleRevision.KB_EDIT_METADATA not in self.utilities.get_page_url():
113124
self.kb_article_page.click_on_edit_article_metadata()
114125

126+
if self.edit_kb_article_page.is_edit_anyway_option_visible():
127+
self.edit_kb_article_page.click_on_edit_anyway_option()
115128
self.kb_article_edit_metadata_page.delete_a_restricted_visibility_group_metadata(
116129
group_name)
117130
self.kb_article_edit_metadata_page.click_on_save_changes_button()

playwright_tests/pages/explore_help_articles/articles/kb_article_page.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, page: Page):
4242
self.editing_tools_show_history_option = page.get_by_role("link", name="Show History",
4343
exact=True)
4444

45-
# Helpfulness widget
45+
# Helpfulness widget section locators.
4646
self.helpfulness_widget = page.locator("form[class='document-vote--form helpful']")
4747
self.helpful_button = page.locator("button[class='btn helpful-button']")
4848
self.unhelpful_button = page.locator("button[class='btn not-helpful-button']")
@@ -54,6 +54,14 @@ def __init__(self, page: Page):
5454
"//div[@class='sumo-button-wrap align-full']/button[normalize-space(text())='Submit']")
5555
self.survey_message = page.locator("div[class='survey-message']")
5656

57+
# Related Articles section locators.
58+
self.related_articles_section = page.locator("section#related-documents")
59+
self.related_article_cards = page.locator("section#related-documents h3.card--title a")
60+
self.related_article = lambda article_title: page.locator(
61+
f'//section[@id="related-documents"]//h3[@class="card--title"]/a[normalize-space('
62+
f'text())="{article_title}"]'
63+
)
64+
5765
# KB Article page content actions.
5866
def click_on_a_particular_breadcrumb(self, breadcrumb_name: str):
5967
self._click(self.article_breadcrumb(breadcrumb_name))
@@ -158,3 +166,13 @@ def click_on_helpfulness_submit_button(self):
158166

159167
def get_survey_message_text(self) -> str:
160168
return self._get_text_of_element(self.survey_message)
169+
170+
def is_related_articles_section_displayed(self) -> bool:
171+
return self._is_element_visible(self.related_articles_section)
172+
173+
def get_list_of_related_articles(self) -> list[str]:
174+
return [article.strip() for article in self._get_text_of_elements(
175+
self.related_article_cards)]
176+
177+
def click_on_related_article_card(self, article_title: str):
178+
self._click(self.related_article(article_title))

playwright_tests/pages/explore_help_articles/articles/kb_edit_article_meta.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def __init__(self, page: Page):
2424
self.allow_discussion_checkbox = page.locator("input#id_allow_discussion")
2525
self.needs_change_checkbox = page.locator("input#id_needs_change")
2626
self.needs_change_textarea = page.locator("textarea#id_needs_change_comment")
27+
self.related_documents_field = page.locator("input#search-related-ts-control")
28+
self.related_documents_search_result = lambda search_term : page.locator(
29+
f'//div[@id="search-related-ts-dropdown"]/div[normalize-space(.)="{search_term}"]'
30+
)
31+
self.related_documents_search_results = page.locator(
32+
"div#search-related-ts-dropdown div")
33+
self.added_related_documents = page.locator("div.ts-control div.item")
34+
self.remove_related_documents_button = lambda related_document: page.locator(
35+
f'//div[@class="item" and text()="{related_document}"]/a')
36+
self.no_results_found_related_documents_message = page.locator(
37+
"div#search-related-ts-dropdown div.no-results")
2738
self.save_changes_button = page.get_by_role("button", name="Save", exact=True)
2839
self.delete_group = lambda chosen_group: page.locator(
2940
f"//input[@id='id_restrict_to_groups-selectized']/../div[text()='{chosen_group}']/a")
@@ -102,6 +113,25 @@ def click_needs_change_checkbox(self):
102113
def fill_needs_change_textarea(self, text: str):
103114
self._fill(self.needs_change_textarea, text)
104115

116+
def add_related_documents(self, document_name: str, submit: bool = True):
117+
self._fill(self.related_documents_field, document_name)
118+
if submit:
119+
self._wait_for_locator(self.related_documents_search_result(document_name), 5000)
120+
self._click(self.related_documents_search_result(document_name))
121+
122+
def is_no_related_documents_displayed(self) -> bool:
123+
return self._is_element_visible(self.no_results_found_related_documents_message)
124+
125+
def get_related_documents_search_options(self) -> list[str]:
126+
return self._get_text_of_elements(self.related_documents_search_results)
127+
128+
def get_related_documents(self) -> list[str]:
129+
return [text.replace("\n×", "").strip() for text in self._get_text_of_elements(
130+
self.added_related_documents)]
131+
132+
def remove_related_document(self, document_name: str):
133+
self._click(self.remove_related_documents_button(document_name))
134+
105135
def click_on_save_changes_button(self):
106136
self._click(self.save_changes_button)
107137
self.wait_for_page_to_load()

playwright_tests/pages/explore_help_articles/articles/kb_edit_article_page.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def get_edit_article_warning_message(self) -> str:
4242
def click_on_edit_anyway_option(self):
4343
self._click(self.edit_by_another_user_edit_anyway_option)
4444

45+
def is_edit_anyway_option_visible(self) -> bool:
46+
return self._is_element_visible(self.edit_by_another_user_edit_anyway_option)
47+
4548
# Edit kb article page field actions.
4649
def get_edit_article_keywords_field_value(self) -> str:
4750
return self._get_element_input_value(self.edit_article_keywords_field)

playwright_tests/test_data/aaq_question.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"valid_firefox_question": {
3-
"subject": "Test Question ",
4-
"subject_updated": "Test Question Updated",
3+
"subject": "NVDA does not work with Firefox ",
4+
"subject_updated": "NVDA does not work with Firefox Updated",
55
"topic_value": "Accessibility",
6-
"question_body": "'''I have a problem''' when I ''access'', the following link: [https://www.mediafax.ro adipiscing], the Firefox browser is not performing is unable to output the messages coming from the screen reader. I've tried reading the following article: [[Stage test owl|sed]] but it doesn't help me understand what is the root cause and how can I fixed the missing content. Can somebody please help me?",
7-
"body_updated": "Updated body",
6+
"question_body": "'''I have a problem''' when I ''access'', the following link: [https://www.mediafax.ro adipiscing], the Firefox browser is unable to output the messages coming from the screen reader. I've tried reading the following article: [[Stage test owl|sed]] but it doesn't help me understand what is the root cause and how can I fix the missing content. Can somebody please help me with this accessibility issue?",
7+
"body_updated": "I have a problem when I access, any links on the internet, the Firefox browser is unable to output the messages coming from the screen reader. I've tried reading an article but it doesn't help me understand what is the root cause and how can I fix the missing content. Can somebody please help me with this accessibility issue? Updated",
88
"simple_body_text": "Firefox doesn't work in combination with the NVDA screen reader",
99
"image_name": "test.image.jpg",
1010
"image_path": "test_data/test-image.png",

playwright_tests/tests/ask_a_question_tests/aaq_tests/test_aaq_form_page.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ def test_post_aaq_questions_for_all_freemium_products_topics(page: Page):
265265
for topic in sumo_pages.aaq_form_page.get_aaq_form_topic_options():
266266
with allure.step(f"Submitting question for {product} product"):
267267
question_info = sumo_pages.aaq_flow.submit_an_aaq_question(
268-
subject=utilities.aaq_question_test_data["valid_firefox_question"]
269-
["subject"],
268+
subject=f"Issue related to the {topic} topic",
270269
topic_name=topic,
271-
body=f"I have a problem with {topic}. It doesn't seem to work whatever I"
272-
f" try to do... Can you please help me?",
270+
body=f"I have a problem related to {topic}. But I don't know how to "
271+
f"explain it properly. I need some guidance in debugging this so "
272+
f"that I can provide more information.",
273273
attach_image=False,
274274
expected_locator=sumo_pages.question_page.questions_header
275275
)

playwright_tests/tests/explore_help_articles_tests/articles/test_kb_article_creation_and_access.py

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,3 +2130,189 @@ def test_voting_the_same_article_twice_is_not_possible(page: Page, context: Brow
21302130
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
21312131
))
21322132
sumo_pages.kb_article_deletion_flow.delete_kb_article()
2133+
2134+
2135+
# C3065908 C3065909
2136+
@pytest.mark.kbArticleCreationAndAccess
2137+
def test_adding_and_removing_related_documents(page: Page):
2138+
utilities = Utilities(page)
2139+
sumo_pages = SumoPages(page)
2140+
test_articles_url = []
2141+
test_article_titles = []
2142+
2143+
with allure.step("Signing in with an admin account"):
2144+
utilities.start_existing_session(utilities.username_extraction_from_email(
2145+
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
2146+
))
2147+
2148+
with allure.step("Creating 3 test articles"):
2149+
counter = 1
2150+
while counter <= 3:
2151+
article_info = sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
2152+
page=page, product="19", topic="507", approve_revision=True)
2153+
test_article_titles.append(article_info["article_title"])
2154+
test_articles_url.append(article_info["article_url"])
2155+
counter += 1
2156+
2157+
with allure.step("Wait for ~1 minute until the kb article is available in search"):
2158+
utilities.wait_for_given_timeout(90000)
2159+
2160+
with allure.step(f"Navigating to the f{test_article_titles[0]} and adding the rest as related "
2161+
f"documents"):
2162+
utilities.navigate_to_link(test_articles_url[0])
2163+
sumo_pages.edit_article_metadata_flow.edit_article_metadata(
2164+
related_documents=test_article_titles[1:]
2165+
)
2166+
2167+
with check, allure.step("Verifying that the related documents are successfully displayed "
2168+
"inside the 'Related Articles' section"):
2169+
check.equal(
2170+
set(test_article_titles[1:]),
2171+
set(sumo_pages.kb_article_page.get_list_of_related_articles())
2172+
)
2173+
2174+
with check, allure.step(f"Clicking on the f{test_article_titles[1]} related document and "
2175+
f"verifying that the article is listed inside the 'Related Articles' "
2176+
f"section"):
2177+
sumo_pages.kb_article_page.click_on_related_article_card(test_article_titles[1])
2178+
check.is_in(
2179+
test_article_titles[0],
2180+
sumo_pages.kb_article_page.get_list_of_related_articles()
2181+
)
2182+
2183+
with allure.step(f"Navigating back to the f{test_article_titles[0]}, clicking on the "
2184+
f"'Edit Article Metadata' and removing one of the related documents"):
2185+
sumo_pages.kb_article_page.click_on_related_article_card(test_article_titles[0])
2186+
sumo_pages.kb_article_page.click_on_edit_article_metadata()
2187+
sumo_pages.kb_article_edit_article_metadata_page.remove_related_document(
2188+
test_article_titles[1])
2189+
sumo_pages.kb_article_edit_article_metadata_page.click_on_save_changes_button()
2190+
2191+
with allure.step(f"Verifying that the f{test_article_titles[1]} is no longer listed inside "
2192+
"'Related Articles' section"):
2193+
check.is_not_in(
2194+
test_article_titles[1],
2195+
sumo_pages.kb_article_page.get_list_of_related_articles()
2196+
)
2197+
2198+
with check, allure.step(f"Navigating to the f{test_article_titles[1]} page and verifying that "
2199+
f"the f{test_article_titles[0]} is not listed inside the "
2200+
f"'Related documents' section"):
2201+
utilities.navigate_to_link(test_articles_url[1])
2202+
check.is_false(
2203+
sumo_pages.kb_article_page.is_related_articles_section_displayed()
2204+
)
2205+
2206+
with allure.step("Deleting all test articles"):
2207+
for article in test_articles_url:
2208+
utilities.navigate_to_link(article)
2209+
sumo_pages.kb_article_deletion_flow.delete_kb_article()
2210+
2211+
2212+
# C3059081
2213+
@pytest.mark.kbArticleCreationAndAccess
2214+
def test_same_article_cannot_be_added_as_related_article(page: Page):
2215+
utilities = Utilities(page)
2216+
sumo_pages = SumoPages(page)
2217+
2218+
with allure.step("Signing in with an admin account"):
2219+
utilities.start_existing_session(utilities.username_extraction_from_email(
2220+
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
2221+
))
2222+
2223+
with allure.step("Creating a new KB article"):
2224+
article_info = sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
2225+
page=page, product="19", topic="507", approve_revision=True)
2226+
2227+
with allure.step("Wait for ~1 minute until the kb article is available in search"):
2228+
utilities.wait_for_given_timeout(90000)
2229+
2230+
with check, allure.step("Clicking on the 'Edit Article Metadata' option and verifying that "
2231+
"the same article cannot be added inside the 'Related documents' "
2232+
"field"):
2233+
sumo_pages.kb_article_page.click_on_edit_article_metadata()
2234+
sumo_pages.kb_article_edit_article_metadata_page.add_related_documents(
2235+
article_info["article_title"], submit=False)
2236+
utilities.wait_for_given_timeout(2000)
2237+
check.is_true(
2238+
sumo_pages.kb_article_edit_article_metadata_page.is_no_related_documents_displayed()
2239+
)
2240+
2241+
with allure.step("Deleting the KB article"):
2242+
utilities.navigate_to_link(article_info["article_url"])
2243+
sumo_pages.kb_article_deletion_flow.delete_kb_article()
2244+
2245+
2246+
# C3065910
2247+
@pytest.mark.kbArticleCreationAndAccess
2248+
def test_restricted_visibility_related_document_in_article_page(page: Page):
2249+
utilities = Utilities(page)
2250+
sumo_pages = SumoPages(page)
2251+
test_articles_url = []
2252+
test_article_titles = []
2253+
2254+
with allure.step("Signing in with an admin account"):
2255+
utilities.start_existing_session(utilities.username_extraction_from_email(
2256+
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
2257+
))
2258+
2259+
with allure.step("Creating 3 new articles"):
2260+
counter = 1
2261+
while counter <= 3:
2262+
article_info = sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
2263+
page=page, product="19", topic="507", approve_revision=True)
2264+
test_article_titles.append(article_info["article_title"])
2265+
test_articles_url.append(article_info["article_url"])
2266+
counter += 1
2267+
2268+
with allure.step("Wait for ~1 minute until the kb article is available in search"):
2269+
utilities.wait_for_given_timeout(90000)
2270+
2271+
with allure.step(f"Navigating to the article: f{test_article_titles[1]} and "
2272+
f"restricting the visibility of the article to 'Mobile' group"):
2273+
utilities.navigate_to_link(test_articles_url[1])
2274+
sumo_pages.edit_article_metadata_flow.edit_article_metadata(single_group="Mobile")
2275+
2276+
with allure.step(f"Navigating to the: f{test_article_titles[0]} article and adding the rest "
2277+
f"of test articles as related documents"):
2278+
utilities.navigate_to_link(test_articles_url[0])
2279+
sumo_pages.kb_article_page.click_on_edit_article_metadata()
2280+
sumo_pages.edit_article_metadata_flow.edit_article_metadata(
2281+
related_documents=test_article_titles[1:]
2282+
)
2283+
2284+
with allure.step("Signing in with a users that doesn't belong to the 'Mobile' group"):
2285+
utilities.start_existing_session(utilities.username_extraction_from_email(
2286+
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
2287+
))
2288+
2289+
with check, allure.step("Verifying that the article is not displayed inside the 'Related "
2290+
"Documents' section"):
2291+
utilities.navigate_to_link(test_articles_url[0])
2292+
check.is_not_in(
2293+
test_article_titles[1],
2294+
sumo_pages.kb_article_page.get_list_of_related_articles()
2295+
)
2296+
2297+
with check, allure.step(f"Signing in with the account that is part of the 'Mobile' group"
2298+
f"group, navigating to the f{test_article_titles[0]} article and "
2299+
f"verifying that the restricted visibility article is now visible in "
2300+
f"the 'Related Documents' section"):
2301+
utilities.start_existing_session(utilities.username_extraction_from_email(
2302+
utilities.user_secrets_accounts["TEST_ACCOUNT_13"]
2303+
))
2304+
utilities.navigate_to_link(test_articles_url[0])
2305+
check.is_in(
2306+
test_article_titles[1],
2307+
sumo_pages.kb_article_page.get_list_of_related_articles()
2308+
)
2309+
2310+
with allure.step("Deleting all test articles"):
2311+
with allure.step("Signing in with an admin account"):
2312+
utilities.start_existing_session(utilities.username_extraction_from_email(
2313+
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
2314+
))
2315+
2316+
for article in test_articles_url:
2317+
utilities.navigate_to_link(article)
2318+
sumo_pages.kb_article_deletion_flow.delete_kb_article()

0 commit comments

Comments
 (0)