Skip to content

Commit e9c8698

Browse files
authored
Merge pull request #7290 from emilghittasv/playwright-expand-test-coverage
Playwright expand test coverage for anti-spam and question reply voting
2 parents 2029f1d + 8a7d399 commit e9c8698

File tree

5 files changed

+188
-91
lines changed

5 files changed

+188
-91
lines changed

playwright_tests/flows/ask_a_question_flows/aaq_flows/aaq_flow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ def editing_reply_flow(self, answer_id: str, reply_body: str, submit_reply=True)
159159
reply_body (str): The new reply body content.
160160
submit_reply: If the edits should be submitted or not.
161161
"""
162-
self.question_page.click_on_reply_more_options_button(answer_id)
163-
self.question_page.click_on_edit_this_post_for_a_certain_reply(answer_id)
162+
if self.aaq_form_page.form_update_answer_button.is_hidden():
163+
self.question_page.click_on_reply_more_options_button(answer_id)
164+
self.question_page.click_on_edit_this_post_for_a_certain_reply(answer_id)
164165

165166
self.aaq_form_page.clear_the_question_body_textarea_field()
166167
self.aaq_form_page.add_text_to_aaq_textarea_field(reply_body)
@@ -184,7 +185,7 @@ def delete_question_reply(self, answer_id: str, delete_reply: bool):
184185

185186
@retry_on_502
186187
def post_question_reply_flow(self, repliant_username: str, reply='', submit_reply=True,
187-
quoted_reply=False, reply_for_id='') -> str:
188+
quoted_reply=False, reply_for_id='', fetch_id=True) -> str:
188189
"""
189190
Flow for posting a question reply.
190191
Args:
@@ -206,7 +207,7 @@ def post_question_reply_flow(self, repliant_username: str, reply='', submit_repl
206207
self.question_page.add_text_to_post_a_reply_textarea(reply)
207208

208209
if submit_reply:
209-
return self.question_page.click_on_post_reply_button(repliant_username)
210+
return self.question_page.click_on_post_reply_button(repliant_username, fetch_id)
210211

211212
def report_question_abuse(self, answer_id: str, text=''):
212213
"""

playwright_tests/pages/ask_a_question/posted_question_pages/questions_page.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ def __init__(self, page: Page):
234234
def get_text_of_spam_marked_banner(self) -> str:
235235
return self._get_text_of_element(self.reply_flagged_as_spam_banner)
236236

237-
def is_spam_marked_banner_displayed(self) -> bool:
238-
return self._is_element_visible(self.reply_flagged_as_spam_banner)
239237

240238
"""Actions against the report abuse section locators."""
241239
def click_abuse_modal_close_button(self):
@@ -423,10 +421,16 @@ def get_blockquote_reply_text(self, reply_id: str) -> str:
423421
def get_posted_reply_modified_by_text(self, reply_id: str) -> str:
424422
return self._get_text_of_element(self.modified_by_text(reply_id))
425423

426-
def click_on_post_reply_button(self, repliant_username) -> str:
424+
def click_on_post_reply_button(self, repliant_username, fetch_id: bool) -> str:
425+
"""Post the question reply.
426+
Args:
427+
repliant_username (str): The username of the repliant. Acts as a wait.
428+
fetch_id (bool): If we should return the question reply id or not.
429+
"""
427430
self._click(self.post_reply_button,
428431
expected_locator=self.repliant_username(repliant_username))
429-
return self._get_element_attribute_value(self.answer_by_username(repliant_username), "id")
432+
if fetch_id:
433+
return self._get_element_attribute_value(self.answer_by_username(repliant_username), "id")
430434

431435
"""Actions against the question tools section locators."""
432436
def get_thread_locked_text(self) -> str:

playwright_tests/tests/ask_a_question_tests/aaq_tests/test_anti_spam_measures.py

Lines changed: 144 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import random
12
import allure
23
import pytest
3-
from playwright.sync_api import Page
4+
from playwright.sync_api import Page, expect
45
from pytest_check import check
56
from playwright_tests.core.utilities import Utilities
67
from playwright_tests.messages.ask_a_question_messages.AAQ_messages.question_page_messages import (
78
QuestionPageMessages,
89
)
910
from playwright_tests.messages.common_elements_messages import CommonElementsMessages
1011
from playwright_tests.pages.sumo_pages import SumoPages
12+
from kitsune.settings import TRUSTED_GROUPS
1113

1214

1315
# C946237
@@ -51,16 +53,16 @@ def test_anti_spam_banner(page: Page, user_type, create_user_factory):
5153
CommonElementsMessages.AVOID_SCAM_BANNER_TEXT)
5254

5355

54-
# C946274
56+
# C946275
5557
@pytest.mark.smokeTest
5658
@pytest.mark.antiSpamTests
57-
def test_valid_tld_in_question_comment(page: Page, create_user_factory):
59+
def test_spam_content_is_auto_flagged(page: Page, create_user_factory):
5860
sumo_pages = SumoPages(page)
5961
utilities = Utilities(page)
60-
invalid_tld = "dom.ipc.processCount"
61-
valid_tld = "layout.display-list.retain.chrome"
6262
test_user = create_user_factory(groups=["Forum Moderators"])
6363
test_user_two = create_user_factory()
64+
spam_content = ['https://www.example.com', 'layout.display-list.retain.chrome',
65+
'800, 888, 877, 866, 855, 844, or 833', '+1 212-555-1234']
6466

6567
with allure.step("Signing in with a Forum Moderator account and creating an AAQ question"):
6668
utilities.start_existing_session(cookies=test_user)
@@ -74,38 +76,150 @@ def test_valid_tld_in_question_comment(page: Page, create_user_factory):
7476
expected_locator=sumo_pages.question_page.questions_header
7577
)
7678

77-
with allure.step("Signing in with an account that doesn't have the bypass ratelimit "
78-
"permission"):
79-
utilities.start_existing_session(cookies=test_user_two)
79+
for content in spam_content:
80+
with allure.step("Signing in with an account that doesn't have the bypass ratelimit "
81+
"permission"):
82+
utilities.start_existing_session(cookies=test_user_two)
8083

81-
with allure.step("Leaving a comment with an invalid TLD"):
82-
reply_one = sumo_pages.aaq_flow.post_question_reply_flow(
83-
repliant_username=test_user_two["username"], reply=invalid_tld
84-
)
84+
with allure.step(f"Leaving a comment with {content} spam content"):
85+
sumo_pages.aaq_flow.post_question_reply_flow(
86+
repliant_username=test_user_two["username"], reply=content, fetch_id=False
87+
)
88+
89+
with check, allure.step("Verifying that the spam banner is successfully displayed"):
90+
assert (QuestionPageMessages.SPAM_FLAGGED_REPLY == sumo_pages.question_page.
91+
get_text_of_spam_marked_banner())
92+
93+
with check, allure.step(f"Verifying that the comment is marked as spam"):
94+
assert not sumo_pages.question_page.is_reply_with_content_displayed(content)
95+
96+
with check, allure.step("Signing out and verifying that the reply is not displayed"):
97+
utilities.delete_cookies()
98+
assert not sumo_pages.question_page.is_reply_with_content_displayed(content)
99+
100+
with check, allure.step("Signing in with an admin account and verifying that the Marked as "
101+
"spam reply is visible"):
102+
utilities.start_existing_session(cookies=test_user)
103+
assert sumo_pages.question_page.is_reply_with_content_displayed(content)
85104

86-
with check, allure.step("Verifying that the spam banner is not displayed"):
87-
assert not sumo_pages.question_page.is_spam_marked_banner_displayed()
88105

89-
with check, allure.step("Verifying that the invalid TLD comment is not marked as spam"):
90-
assert sumo_pages.question_page.is_reply_displayed(reply_one)
106+
# C946276
107+
@pytest.mark.antiSpamTests
108+
def test_valid_prefs_and_internal_links_are_not_flagged_as_spam(page: Page, create_user_factory):
109+
sumo_pages = SumoPages(page)
110+
utilities = Utilities(page)
111+
test_user = create_user_factory(groups=["Forum Moderators"])
112+
test_user_two = create_user_factory()
113+
test_content = ['https://support.mozilla.org', 'dom.ipc.processCount']
91114

92-
with allure.step("Leaving a comment with a valid TLD"):
93-
sumo_pages.aaq_flow.post_question_reply_flow(
94-
repliant_username=test_user_two["username"], reply=valid_tld
115+
with allure.step("Signing in with a Forum Moderator account and creating an AAQ question"):
116+
utilities.start_existing_session(cookies=test_user)
117+
118+
utilities.navigate_to_link(utilities.aaq_question_test_data["products_aaq_url"]["Firefox"])
119+
sumo_pages.aaq_flow.submit_an_aaq_question(
120+
subject=utilities.aaq_question_test_data["valid_firefox_question"]["subject"],
121+
topic_name=sumo_pages.aaq_form_page.get_aaq_form_topic_options()[0],
122+
body=utilities.aaq_question_test_data["valid_firefox_question"]["question_body"],
123+
attach_image=False,
124+
expected_locator=sumo_pages.question_page.questions_header
95125
)
96126

97-
with check, allure.step("Verifying that the spam banner is successfully displayed"):
98-
assert (QuestionPageMessages.SPAM_FLAGGED_REPLY == sumo_pages.question_page.
99-
get_text_of_spam_marked_banner())
127+
for content in test_content:
128+
with allure.step("Signing in with an account that doesn't have the bypass ratelimit "
129+
"permission"):
130+
utilities.start_existing_session(cookies=test_user_two)
100131

101-
with check, allure.step("Verifying that the valid TLD comment is marked as spam"):
102-
assert not sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)
132+
with allure.step(f"Leaving a comment with {content} spam content"):
133+
reply_id = sumo_pages.aaq_flow.post_question_reply_flow(
134+
repliant_username=test_user_two["username"], reply=content,
135+
)
103136

104-
with check, allure.step("Signing out and verifying that the reply is not displayed"):
105-
utilities.delete_cookies()
106-
assert not sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)
137+
with check, allure.step("Verifying that the spam banner is not displayed"):
138+
expect(sumo_pages.question_page.reply_flagged_as_spam_banner).to_be_hidden()
139+
140+
with check, allure.step(f"Verifying that the valid pref value comment is displayed"):
141+
assert sumo_pages.question_page.is_reply_displayed(reply_id)
142+
143+
with check, allure.step("Signing out and verifying that the reply is displayed"):
144+
utilities.delete_cookies()
145+
assert sumo_pages.question_page.is_reply_displayed(reply_id)
146+
147+
148+
# C1296001, C3395616
149+
@pytest.mark.antiSpamTests
150+
def test_question_owner_is_exempted_for_spam_auto_flag(page: Page, create_user_factory):
151+
utilities = Utilities(page)
152+
sumo_pages = SumoPages(page)
153+
spam_content = ['https://www.example.com', 'layout.display-list.retain.chrome',
154+
'800, 888, 877, 866, 855, 844, or 833', '+1 212-555-1234']
155+
test_user = create_user_factory()
156+
157+
with allure.step("Signing in creating an AAQ question"):
158+
utilities.start_existing_session(cookies=test_user)
107159

108-
with check, allure.step("Signing in with an admin account and verifying that the Marked as "
109-
"spam reply is visible"):
160+
utilities.navigate_to_link(
161+
utilities.aaq_question_test_data["products_aaq_url"]["Firefox"])
162+
sumo_pages.aaq_flow.submit_an_aaq_question(
163+
subject=utilities.aaq_question_test_data["valid_firefox_question"]["subject"],
164+
topic_name=sumo_pages.aaq_form_page.get_aaq_form_topic_options()[0],
165+
body=utilities.
166+
aaq_question_test_data["valid_firefox_question"]["question_body"] + spam_content[1],
167+
attach_image=False,
168+
expected_locator=sumo_pages.question_page.questions_header
169+
)
170+
171+
for content in spam_content:
172+
with allure.step(f"Leaving a comment with a spam comment"):
173+
reply_id = sumo_pages.aaq_flow.post_question_reply_flow(
174+
repliant_username=test_user["username"], reply=content
175+
)
176+
177+
with check, allure.step("Verifying that the spam banner is not displayed"):
178+
expect(sumo_pages.question_page.reply_flagged_as_spam_banner).to_be_hidden()
179+
180+
with check, allure.step(f"Verifying that the comment is displayed"):
181+
assert sumo_pages.question_page.is_reply_displayed(reply_id)
182+
183+
184+
# C3395573, C3395578
185+
@pytest.mark.antiSpamTests
186+
@pytest.mark.parametrize("trusted_user_config", [
187+
{"groups": [random.choice(TRUSTED_GROUPS)]},
188+
{"permissions": ["can_moderate"]}
189+
])
190+
def test_trusted_contributors_are_exempted_from_spam_check(page: Page, create_user_factory,
191+
trusted_user_config):
192+
utilities = Utilities(page)
193+
sumo_pages = SumoPages(page)
194+
test_user = create_user_factory()
195+
trusted_group_user = create_user_factory(**trusted_user_config)
196+
spam_content = ['https://www.example.com', 'layout.display-list.retain.chrome',
197+
'800, 888, 877, 866, 855, 844, or 833', '+1 212-555-1234']
198+
199+
with allure.step("Signing in creating an AAQ question"):
110200
utilities.start_existing_session(cookies=test_user)
111-
assert sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)
201+
202+
utilities.navigate_to_link(
203+
utilities.aaq_question_test_data["products_aaq_url"]["Firefox"])
204+
sumo_pages.aaq_flow.submit_an_aaq_question(
205+
subject=utilities.aaq_question_test_data["valid_firefox_question"]["subject"],
206+
topic_name=sumo_pages.aaq_form_page.get_aaq_form_topic_options()[0],
207+
body=utilities.aaq_question_test_data["valid_firefox_question"]["question_body"],
208+
attach_image=False,
209+
expected_locator=sumo_pages.question_page.questions_header
210+
)
211+
212+
for content in spam_content:
213+
with allure.step("Signing in with a trusted user"):
214+
utilities.start_existing_session(cookies=trusted_group_user)
215+
216+
with allure.step(f"Leaving a comment with a spam comment"):
217+
reply_id = sumo_pages.aaq_flow.post_question_reply_flow(
218+
repliant_username=trusted_group_user["username"], reply=content
219+
)
220+
221+
with check, allure.step("Verifying that the spam banner is not displayed"):
222+
expect(sumo_pages.question_page.reply_flagged_as_spam_banner).to_be_hidden()
223+
224+
with check, allure.step(f"Verifying that the comment is displayed"):
225+
assert sumo_pages.question_page.is_reply_displayed(reply_id)

playwright_tests/tests/ask_a_question_tests/aaq_tests/test_posted_questions.py

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,9 +1388,31 @@ def test_quote_reply_functionality_signed_out(page: Page, create_user_factory):
13881388
expect(sumo_pages.question_page.post_a_reply_textarea).to_be_visible()
13891389

13901390

1391-
# T5696770
1392-
@pytest.mark.skip
1393-
# Currently fails due to https://github.com/mozilla/sumo/issues/1216
1391+
# C3186666
1392+
@pytest.mark.postedQuestions
1393+
def test_answer_voting_is_not_available_for_signed_out_users(page: Page, create_user_factory):
1394+
utilities = Utilities(page)
1395+
sumo_pages = SumoPages(page)
1396+
test_user = create_user_factory()
1397+
1398+
with allure.step("Signing in with a simple user account and posting a Firefox product "
1399+
"question"):
1400+
post_firefox_product_question_flow(page, test_user)
1401+
sumo_pages.question_page.get_question_id()
1402+
1403+
with allure.step("Posting a reply to the question"):
1404+
reply_id = sumo_pages.aaq_flow.post_question_reply_flow(
1405+
test_user['username'],
1406+
utilities.aaq_question_test_data['valid_firefox_question']['question_reply'])
1407+
1408+
with allure.step("Signing out and verifying that logged out users are not able to vote "
1409+
"question replies"):
1410+
utilities.delete_cookies()
1411+
expect(sumo_pages.question_page.reply_vote_section(reply_id)).to_be_hidden()
1412+
1413+
1414+
# C937575
1415+
@pytest.mark.postedQuestions
13941416
def test_question_reply_votes(page: Page, create_user_factory):
13951417
utilities = Utilities(page)
13961418
sumo_pages = SumoPages(page)
@@ -1406,10 +1428,9 @@ def test_question_reply_votes(page: Page, create_user_factory):
14061428
sumo_pages.question_page.get_question_id()
14071429

14081430
with allure.step("Posting a reply to the question"):
1409-
sumo_pages.question_page.add_text_to_post_a_reply_textarea(
1410-
utilities.aaq_question_test_data['valid_firefox_question']['question_reply']
1411-
)
1412-
reply_id = sumo_pages.question_page.click_on_post_reply_button(test_user["username"])
1431+
reply_id = sumo_pages.aaq_flow.post_question_reply_flow(
1432+
test_user['username'],
1433+
utilities.aaq_question_test_data['valid_firefox_question']['question_reply'])
14131434

14141435
with allure.step("Verifying the vote reply is not available for self posted questions"):
14151436
expect(sumo_pages.question_page.reply_vote_section(reply_id)).to_be_hidden()
@@ -1447,49 +1468,6 @@ def test_question_reply_votes(page: Page, create_user_factory):
14471468
expect(sumo_pages.question_page.reply_vote_thumbs_down(reply_id)
14481469
).to_have_attribute(name="disabled",value="")
14491470

1450-
with check, allure.step("Refreshing the page and verifying that the correct number of "
1451-
"thumbs up votes is displayed"):
1452-
utilities.refresh_page()
1453-
assert (int(sumo_pages.question_page.
1454-
get_helpful_count(reply_id)) == number_of_thumbs_up_votes)
1455-
1456-
with check, allure.step("Verifying that the correct number of thumbs down votes is "
1457-
"displayed"):
1458-
assert (int(sumo_pages.question_page.
1459-
get_not_helpful_count(reply_id)) == number_of_thumbs_down_votes)
1460-
1461-
with allure.step("Deleting the user session and clicking on the 'thumbs up' button"):
1462-
utilities.delete_cookies()
1463-
sumo_pages.question_page.click_reply_vote_thumbs_up_button(reply_id)
1464-
number_of_thumbs_up_votes += 1
1465-
1466-
with check, allure.step("Refreshing the page and verifying that the correct number of "
1467-
"thumbs up votes is displayed"):
1468-
utilities.refresh_page()
1469-
assert (int(sumo_pages.question_page.
1470-
get_helpful_count(reply_id)) == number_of_thumbs_up_votes)
1471-
1472-
with check, allure.step("Verifying that the correct number of thumbs down votes is "
1473-
"displayed"):
1474-
assert (int(sumo_pages.question_page.
1475-
get_not_helpful_count(reply_id)) == number_of_thumbs_down_votes)
1476-
1477-
with allure.step("Verifying that the thumbs up button contains the disabled attribute"):
1478-
expect(sumo_pages.question_page.reply_vote_thumbs_up(reply_id)
1479-
).to_have_attribute(name="disabled", value="")
1480-
1481-
with allure.step("Verifying that the thumbs down button contains the disabled attribute"):
1482-
expect(sumo_pages.question_page.reply_vote_thumbs_down(reply_id)
1483-
).to_have_attribute(name="disabled", value="")
1484-
1485-
with check, allure.step("Refreshing the page and verifying that the correct number of "
1486-
"thumbs up votes is displayed"):
1487-
utilities.refresh_page()
1488-
assert (int(sumo_pages.question_page.
1489-
get_helpful_count(reply_id)) == number_of_thumbs_up_votes)
1490-
assert (int(sumo_pages.question_page.
1491-
get_not_helpful_count(reply_id)) == number_of_thumbs_down_votes)
1492-
14931471
with allure.step("Signing in with a Forum Moderator account and clicking on the vote down "
14941472
"button"):
14951473
utilities.start_existing_session(cookies=test_user_three)
@@ -1716,10 +1694,10 @@ def test_common_responses(page: Page, create_user_factory):
17161694
sumo_pages.question_page.click_on_common_responses_insert_response_button()
17171695
try:
17181696
reply_id = sumo_pages.question_page.click_on_post_reply_button(
1719-
test_user_two["username"])
1697+
test_user_two["username"], fetch_id=True)
17201698
except TimeoutError:
17211699
reply_id = sumo_pages.question_page.click_on_post_reply_button(
1722-
test_user_two["username"])
1700+
test_user_two["username"], fetch_id=True)
17231701
assert sumo_pages.question_page.get_text_content_of_reply(
17241702
reply_id).strip() in response.strip()
17251703

playwright_tests/tests/ask_a_question_tests/community_forums/test_community_forums_by_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from playwright_tests.pages.sumo_pages import SumoPages
1111

1212

13-
# C3040845
13+
# C3040845. C891278, C891277
1414
@pytest.mark.communityForums
1515
def test_product_community_cards_are_redirecting_to_the_correct_forum(page: Page):
1616
sumo_pages = SumoPages(page)

0 commit comments

Comments
 (0)