Skip to content

Commit 24baeae

Browse files
authored
Merge pull request #7334 from emilghittasv/improve-playwright-tests
Improve playwright tests
2 parents 52d248b + c0e648c commit 24baeae

File tree

12 files changed

+36
-43
lines changed

12 files changed

+36
-43
lines changed

playwright_tests/pages/ask_a_question/posted_question_pages/questions_page.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, page: Page):
9090
f"//a[@class='tag-name' and normalize-space(text())='{tag_name}']"
9191
)
9292
self.delete_tag = lambda tag_name: page.locator(
93-
"//a[@class='tag-name' and normalize-space(text())='test']/following-sibling::"
93+
f"//a[@class='tag-name' and normalize-space(text())='{tag_name}']/following-sibling::"
9494
"a[@class='remove']")
9595

9696
"""Locators belonging to the post a reply section."""
@@ -336,15 +336,15 @@ def get_question_tag_options(self, is_moderator: bool) -> list[str]:
336336
.question_tags_options_for_non_moderators)]
337337

338338
def add_text_to_add_a_tag_input_field(self, text: str):
339-
self._fill(self.add_a_tag_input_field, text)
339+
self._type(self.add_a_tag_input_field, text, 1000)
340340
self._wait_for_given_timeout(2000)
341341
self._press_a_key(self.add_a_tag_input_field, "Enter")
342342

343343
def click_on_a_certain_tag(self, tag_name: str, expected_locator):
344344
self._click(self.tag_by_name(tag_name), expected_locator=expected_locator)
345345

346346
def click_on_tag_remove_button(self, tag_name: str):
347-
self._click(self.delete_tag(tag_name))
347+
self._click(self.delete_tag(tag_name), expected_locator_to_be_hidden=self.tag(tag_name))
348348

349349
"""Actions against the more information section locators."""
350350
def get_user_agent_information(self) -> str:

playwright_tests/pages/common_elements/common_web_elements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, page: Page):
1010

1111
"""Locators belonging to the spam banner."""
1212
self.scam_banner = page.locator("div#id_scam_alert")
13-
self.scam_banner_text = page.locator("div#id_scam_alert p[class='heading']")
13+
self.scam_banner_text = page.locator("//div[@id='id_scam_alert']//p[@class='heading']")
1414
self.learn_more_button = page.locator("div#id_scam_alert").get_by_role("link")
1515

1616
"""Locators belonging to the Still need help widget."""
@@ -64,7 +64,7 @@ def __init__(self, page: Page):
6464
"""Actions against the Avoid Spam banner locators."""
6565
def get_scam_banner_text(self) -> str:
6666
"""Returns the scam banner text."""
67-
return self._get_text_of_element(self.scam_banner_text)
67+
return self._get_text_of_element(self.scam_banner_text).strip()
6868

6969
"""Actions against the Still Need Help widget locators."""
7070
def click_on_aaq_button(self):

playwright_tests/pages/user_pages/my_profile_edit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, page: Page):
5050
"p.delete-account-link a")
5151
self.close_account_username_modal = page.locator("input#delete-profile-confirmation-input")
5252
self.close_account_username_modal_confirmation_code = page.locator(
53-
"//div[@id='delete-profile']//strong")
53+
"//div[@data-modal-id='delete-profile']//strong")
5454
self.close_account_delete_button = page.locator("button#delete-profile-button")
5555
self.close_modal_button = page.locator("button[class='mzp-c-modal-button-close']")
5656

playwright_tests/pages/user_pages/my_profile_page.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, page: Page):
2121
self.private_message_button = page.locator("p.pm").get_by_role("link")
2222

2323
"""Locators belonging to the 'Report Abuse' section."""
24-
self.report_abuse_panel = page.locator("section#report-abuse-")
24+
self.report_abuse_panel = page.locator("//section[@data-modal-id='report-abuse-']")
2525
self.spam_or_other_unrelated_content_option = page.locator("label").filter(
2626
has_text="Spam or other unrelated content")
2727
self.inappropriate_language_or_dialog_option = page.locator("label").filter(
@@ -212,10 +212,6 @@ def click_on_people_directory_link(self):
212212
"""Click on the people directory link."""
213213
self._click(self.people_directory_info)
214214

215-
def click_on_element(self, element: ElementHandle):
216-
"""Click on the given element."""
217-
element.click()
218-
219215
def click_my_profile_page_sign_out_button(self, expected_url=None):
220216
"""Click on the profile page sign out button.
221217

playwright_tests/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ markers =
3535
smokeTest: Tests belonging to the smoke test suite.
3636
userDeletion: Tests belonging to the user deletion suite.
3737
communityForums: Tests belonging to the community forums suite.
38-
addopts = --alluredir=./reports/allure_reports --tb=no
38+
addopts = --alluredir=./reports/allure_reports --video retain-on-failure --tb=no

playwright_tests/test_data/profile_edit.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"close_account_page": "https://support.allizom.org/en-US/users/close_account",
32
"valid_user_edit": {
43
"username": "modifiedUsernameAutoTestt",
54
"display_name": "Modified display name",

playwright_tests/tests/ask_a_question_tests/product_solutions_page_tests/test_product_solutions_page.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ def test_featured_articles_redirect(page: Page, is_chromium):
2929

3030
with allure.step("Clicking on all product cards"):
3131
for card in sumo_pages.contact_support_page.get_all_product_card_titles():
32+
redirect_target = utilities.general_test_data['subscription_redirects'].get(card)
3233
with check, allure.step(f"Clicking on the {card} and verifying that the correct"
3334
f" product solutions page header is displayed"):
3435
sumo_pages.contact_support_page.click_on_a_particular_card(card)
35-
assert sumo_pages.product_solutions_page.get_product_solutions_heading(
36-
) == card + ProductSolutionsMessages.PAGE_HEADER
36+
37+
if redirect_target:
38+
assert sumo_pages.product_solutions_page.get_product_solutions_heading(
39+
) == redirect_target + ProductSolutionsMessages.PAGE_HEADER
40+
else:
41+
assert sumo_pages.product_solutions_page.get_product_solutions_heading(
42+
) == card + ProductSolutionsMessages.PAGE_HEADER
3743

3844
if sumo_pages.product_solutions_page.is_featured_article_section_displayed():
3945
for featured_article_card in (sumo_pages.product_solutions_page

playwright_tests/tests/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ def pytest_runtest_makereport(item, call) -> None:
7676

7777

7878
@pytest.fixture()
79-
def browser_context_args(browser_context_args, tmpdir_factory: pytest.TempdirFactory):
79+
def browser_context_args(browser_context_args):
8080
"""
81-
Modifying the default browser context to include the location of the browser session screencast
82-
and the custom user agent.
81+
Modifying the default browser context to include the custom user agent.
8382
"""
8483
return {
8584
"user_agent": Utilities.user_agent,
8685
**browser_context_args,
87-
"record_video_dir": tmpdir_factory.mktemp('videos')
8886
}
8987

9088

playwright_tests/tests/messaging_system_tests/test_messaging_system.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -810,20 +810,20 @@ def test_staff_users_can_send_messages_to_both_groups_and_user(page: Page, creat
810810
def test_removed_group_users_do_not_receive_group_messages(page: Page, create_user_factory):
811811
utilities = Utilities(page)
812812
sumo_pages = SumoPages(page)
813-
test_user = create_user_factory(groups=["Staff"], permissions=["change_groupprofile"])
814-
test_user_two = create_user_factory(
813+
test_user = create_user_factory(
815814
groups=[utilities.user_message_test_data['test_groups'][0]])
816-
test_user_three = create_user_factory(
815+
test_user_two = create_user_factory(
817816
groups=[utilities.user_message_test_data['test_groups'][0]])
818817
message_body = "Test " + utilities.generate_random_number(1, 1000)
819818
targeted_test_group = utilities.user_message_test_data['test_groups'][0]
820819

821820
with allure.step("Signing in with a staff account and removing a user from the targeted "
822821
"group"):
823-
utilities.start_existing_session(cookies=test_user)
822+
utilities.start_existing_session(
823+
session_file_name=utilities.username_extraction_from_email(utilities.staff_user))
824824
utilities.navigate_to_link(utilities.general_test_data['groups'])
825825
sumo_pages.user_groups.click_on_a_particular_group(targeted_test_group)
826-
sumo_pages.user_group_flow.remove_a_user_from_group(test_user_two["username"])
826+
sumo_pages.user_group_flow.remove_a_user_from_group(test_user["username"])
827827

828828
with allure.step("Navigating to the new message page and sending a message to the group"):
829829
sumo_pages.top_navbar.click_on_inbox_option()
@@ -834,14 +834,14 @@ def test_removed_group_users_do_not_receive_group_messages(page: Page, create_us
834834
expected_url=SentMessagesPageMessages.SENT_MESSAGES_PAGE_URL
835835
)
836836

837-
with allure.step(f"Signing in with {test_user_three['username']} user which is still part of "
837+
with allure.step(f"Signing in with {test_user_two['username']} user which is still part of "
838838
f"the group and verifying that the message was received"):
839-
utilities.start_existing_session(cookies=test_user_three)
839+
utilities.start_existing_session(cookies=test_user_two)
840840
sumo_pages.top_navbar.click_on_inbox_option()
841841
expect(sumo_pages.inbox_page.inbox_message_by_excerpt(message_body)).to_be_visible()
842842

843843
with allure.step("Verifying that the removed user has not received the group message"):
844-
utilities.start_existing_session(cookies=test_user_two)
844+
utilities.start_existing_session(cookies=test_user)
845845
expect(sumo_pages.inbox_page.inbox_message_by_excerpt(message_body)).to_be_hidden()
846846

847847

playwright_tests/tests/user_deletion_tests/kb/test_user_deletion_and_article_contributions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_localization_revisions_are_assigned_to_system_account(page: Page, creat
159159
def test_reviewed_by_assignment_to_system_account(page: Page, create_user_factory):
160160
utilities = Utilities(page)
161161
sumo_pages = SumoPages(page)
162-
test_user = create_user_factory()
162+
test_user = create_user_factory(permissions=["delete_document"])
163163
test_user_two = create_user_factory(groups=["Knowledge Base Reviewers"])
164164

165165
with allure.step("Signing in and creating a new kb article"):

0 commit comments

Comments
 (0)