Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright question_page refactor & expand coverage to anti-spam measures #6410

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ on:
- exploreByTopics
- searchTests
- userGroupsTests
- antiSpamTests

env:
TEST_ACCOUNT_12: ${{secrets.AUTOMATION_TEST_ACCOUNT_12}}
Expand Down Expand Up @@ -104,7 +105,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" "productSupportPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics" "searchTests" "userGroupsTests")
declare all_test_suites=("homePageTests" "topNavbarTests" "footerSectionTests" "contributePagesTests" "messagingSystem" "messagingSystemCleanup" "userContributionTests" "userProfile" "userSettings" "editUserProfileTests" "userQuestions" "contactSupportPage" "productSolutionsPage" "productSupportPage" "productTopicsPage" "aaqPage" "postedQuestions" "kbProductsPage" "kbArticleCreationAndAccess" "beforeThreadTests" "articleThreads" "afterThreadTests" "kbArticleShowHistory" "recentRevisionsDashboard" "kbDashboard" "kbRestrictedVisibility" "kbArticleTranslation" "exploreByTopics" "searchTests" "userGroupsTests", "antiSpamTests")
if [ "$dispatch_test_suite" == "All" ] || [ "${{ github.event_name}}" == "schedule" ] ; then
for test in "${all_test_suites[@]}"; do
if ! poetry run pytest -m ${test} --numprocesses 6 --browser ${{ env.BROWSER }} --reruns 2; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ class QuestionPageMessages:
"-mozilla-tech-support-scams")
TRY_THESE_MANUAL_STEPS_LINK = ("https://support.mozilla.org/kb/use-troubleshooting"
"-information-page-fix-firefox")
SPAM_FLAGGED_REPLY = "A moderator must manually approve your post before it will be visible."
4 changes: 4 additions & 0 deletions playwright_tests/messages/common_elements_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CommonElementsMessages:
AVOID_SCAM_BANNER_TEXT = ("Avoid support scams. We will never ask you to call or text a phone "
"number or share personal information. Please report suspicious "
"activity using the “Report Abuse” option.")

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions playwright_tests/pages/common_elements/common_web_elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from playwright.sync_api import Page
from playwright_tests.core.basepage import BasePage


class CommonWebElements(BasePage):
AVOID_SPAM_BANNER = {
"scam_banner": "//div[@id='id_scam_alert']",
"scam_banner_text": "//div[@id='id_scam_alert']//p[@class='heading']",
"learn_more_button": "//div[@id='id_scam_alert']//a"
}

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

# Actions against the Avoid Spam Banner
def get_scam_banner_text(self) -> str:
"""Returns the scam banner text."""
return self._get_text_of_element(self.AVOID_SPAM_BANNER["scam_banner_text"])
5 changes: 4 additions & 1 deletion playwright_tests/pages/sumo_pages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from playwright.sync_api import Page

from playwright_tests.flows.ask_a_question_flows.aaq_flows.aaq_flow import AAQFlow
from playwright_tests.flows.explore_articles_flows.article_flows.add_kb_article_flow import (
AddKbArticleFlow)
Expand All @@ -19,6 +18,7 @@
from playwright_tests.flows.user_groups_flows.user_group_flow import UserGroupFlow
from playwright_tests.flows.user_profile_flows.edit_profile_data_flow import EditProfileDataFlow
from playwright_tests.pages.ask_a_question.aaq_pages.aaq_form_page import AAQFormPage
from playwright_tests.pages.common_elements.common_web_elements import CommonWebElements
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions_pages.\
contributor_discussions_page import ContributorDiscussionPage
from playwright_tests.pages.contribute.contribute_pages.contributor_discussions_pages.\
Expand Down Expand Up @@ -225,3 +225,6 @@ def __init__(self, page: Page):

# KB article threads Flow
self.kb_article_thread_flow = KbThreads(page)

# Common Web Elements
self.common_web_elements = CommonWebElements(page)
1 change: 1 addition & 0 deletions playwright_tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ markers =
exploreByTopics: Tests belonging to the explore help articles by topics page.
searchTests: Tests belonging to the search functionality.
userGroupsTests: Tests belonging to the user groups section.
antiSpamTests: Tests belonging to the anti-spam measures section.
addopts = --alluredir=./reports/allure_reports --tb=no
9 changes: 9 additions & 0 deletions playwright_tests/test_data/general_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
"Firefox Focus": "https://support.allizom.org/en-US/questions/new/focus-firefox",
"Mozilla Account": "https://support.allizom.org/en-US/questions/new/mozilla-account"
},
"product_forums" :{
"Firefox": "https://support.allizom.org/en-US/questions/firefox",
"Firefox for Android": "https://support.allizom.org/en-US/questions/mobile",
"Firefox for iOS": "https://support.allizom.org/en-US/questions/ios",
"Firefox for Enterprise": "https://support.allizom.org/en-US/questions/firefox-enterprise",
"Firefox Focus": "https://support.allizom.org/en-US/questions/focus-firefox",
"Thunderbird": "https://support.allizom.org/en-US/questions/thunderbird",
"Thunderbird for Android": "https://support.allizom.org/en-US/questions/thunderbird-android"
},
"dashboard_links": {
"recent_revisions": "https://support.allizom.org/en-US/kb/revisions",
"kb_overview": "https://support.allizom.org/en-US/contributors/kb-overview",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import allure
import pytest
from playwright.sync_api import Page
from playwright_tests.core.utilities import Utilities
from playwright_tests.messages.ask_a_question_messages.AAQ_messages.question_page_messages import \
QuestionPageMessages
from playwright_tests.messages.common_elements_messages import CommonElementsMessages
from playwright_tests.pages.sumo_pages import SumoPages
from pytest_check import check


# C946237
@pytest.mark.antiSpamTests
@pytest.mark.parametrize("username", ['', 'TEST_ACCOUNT_12'])
def test_anti_spam_banner(page: Page, username):
sumo_pages = SumoPages(page)
utilities = Utilities(page)

with allure.step("Signing in with an admin account and creating an AAQ question"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

utilities.navigate_to_link(utilities.aaq_question_test_data["products_aaq_url"]["Firefox"])
question_info_one = sumo_pages.aaq_flow.submit_an_aaq_question(
subject=utilities.aaq_question_test_data["valid_firefox_question"]["subject"],
topic_name=sumo_pages.aaq_form_page.get_aaq_form_topic_options()[0],
body=utilities.aaq_question_test_data["valid_firefox_question"]
["simple_body_text"],
attach_image=False,
expected_locator=sumo_pages.question_page.QUESTION_LOCATORS["questions_header"]
)

if username != '':
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts[username]
))
else:
utilities.delete_cookies()

with allure.step("Navigating to each available product support forum and verifying that the "
"scam banner is displayed"):
for product, url in utilities.general_test_data["product_forums"].items():
utilities.navigate_to_link(url)
assert sumo_pages.common_web_elements.get_scam_banner_text() == (
CommonElementsMessages.AVOID_SCAM_BANNER_TEXT)

with allure.step("Navigating to the posted question and verifying that the scam banner is "
"displayed"):
utilities.navigate_to_link(question_info_one["question_page_url"])
assert sumo_pages.common_web_elements.get_scam_banner_text() == (CommonElementsMessages.
AVOID_SCAM_BANNER_TEXT)

utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
with allure.step("Deleting the posted question"):
sumo_pages.aaq_flow.deleting_question_flow()


# C946274
@pytest.mark.antiSpamTests
def test_valid_tld_in_question_comment(page: Page):
sumo_pages = SumoPages(page)
utilities = Utilities(page)
invalid_tld = "dom.ipc.processCount"
valid_tld = "layout.display-list.retain.chrome"

with allure.step("Signing in with an admin account and creating an AAQ question"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

utilities.navigate_to_link(utilities.aaq_question_test_data["products_aaq_url"]["Firefox"])
sumo_pages.aaq_flow.submit_an_aaq_question(
subject=utilities.aaq_question_test_data["valid_firefox_question"]["subject"],
topic_name=sumo_pages.aaq_form_page.get_aaq_form_topic_options()[0],
body=utilities.aaq_question_test_data["valid_firefox_question"]
["simple_body_text"],
attach_image=False,
expected_locator=sumo_pages.question_page.QUESTION_LOCATORS["questions_header"]
)

with allure.step("Signing in with an account that doesn't have the bypass ratelimit "
"permission"):
username = utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_2"]
))

with allure.step("Leaving a comment with an invalid TLD"):
reply_one = sumo_pages.aaq_flow.post_question_reply_flow(
repliant_username=username,
reply=invalid_tld
)

with check, allure.step("Verifying that the invalid TLD comment is not marked as spam "
"and the spam banner is not displayed"):
assert not sumo_pages.question_page.is_spam_marked_banner_displayed()
assert sumo_pages.question_page.is_reply_displayed(reply_one)

with allure.step("Leaving a comment with a valid TLD"):
sumo_pages.aaq_flow.post_question_reply_flow(
repliant_username=username,
reply=valid_tld
)

with check, allure.step("Verifying that the valid TLD comment is marked as spam and the "
"banner is successfully displayed"):
assert (QuestionPageMessages.SPAM_FLAGGED_REPLY == sumo_pages.question_page.
get_text_of_spam_marked_banner())
assert not sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)

with check, allure.step("Signing out and verifying that the reply is not displayed"):
utilities.delete_cookies()
assert not sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)

with check, allure.step("Signing in with an admin account and verifying that the Marked as"
"spam reply is visible"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
assert sumo_pages.question_page.is_reply_with_content_displayed(valid_tld)

with allure.step("Deleting the question"):
sumo_pages.aaq_flow.deleting_question_flow()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import time

import allure
import pytest
from pytest_check import check
Expand Down