Merge pull request #6200 from emilghittasv/playwright-wait-fixes

Playwright wait strategy & test fixes
This commit is contained in:
Emil Ghitta 2024-08-23 10:45:28 +03:00 коммит произвёл GitHub
Родитель 30d57e5735 c2aeff39b9
Коммит 0d675285e5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
9 изменённых файлов: 103 добавлений и 94 удалений

Просмотреть файл

@ -1,7 +1,7 @@
import random
from typing import Union
from playwright.sync_api import Page, ElementHandle, Locator, TimeoutError
from playwright.sync_api import Page, ElementHandle, Locator
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
class BasePage:
@ -14,14 +14,14 @@ class BasePage:
This helper function returns the element locator from a given xpath.
"""
if with_wait:
self.page.wait_for_selector(xpath)
self.__wait_for_dom_load_to_finish()
return self.page.locator(xpath)
def _get_elements_locators(self, xpath: str) -> list[Locator]:
"""
This helper function returns a list of element locators from a given xpath.
"""
self._wait_for_selector(xpath)
self.__wait_for_dom_load_to_finish()
return self.page.locator(xpath).all()
def _get_current_page_url(self) -> str:
@ -48,14 +48,11 @@ class BasePage:
"""
return self._get_element_locator(xpath).all_inner_texts()
def _get_text_of_element(self, xpath: str, with_wait: bool) -> str:
def _get_text_of_element(self, xpath: str) -> str:
"""
This helper function returns the inner text of a given xpath.
"""
if with_wait:
self._get_element_locator(xpath, with_wait=with_wait).inner_text()
else:
return self._get_element_locator(xpath).inner_text()
return self._get_element_locator(xpath).inner_text()
def _get_text_of_locator(self, locator: Locator) -> str:
"""
@ -83,7 +80,7 @@ class BasePage:
if isinstance(element, str):
return self._get_element_locator(element).get_attribute(attribute)
elif isinstance(element, list):
self.__wait_for_dom_load_to_finnish()
self.__wait_for_dom_load_to_finish()
values = []
for element in element:
values.append(element.get_attribute(attribute))
@ -223,7 +220,7 @@ class BasePage:
"""
return self._get_element_locator(xpath).is_checked()
def __wait_for_dom_load_to_finnish(self):
def __wait_for_dom_load_to_finish(self):
"""
This helper function performs two waits:
1. Waits for the dom load to finish.
@ -239,5 +236,5 @@ class BasePage:
"""
try:
self.page.wait_for_selector(xpath, timeout=timeout)
except TimeoutError:
except PlaywrightTimeoutError:
print(f"{xpath} is not displayed")

Просмотреть файл

@ -159,8 +159,9 @@ class Utilities:
response = navigation_info.value
self.wait_for_dom_to_load()
if response.status >= 400:
self.refresh_page()
if response.status is not None:
if response.status >= 400:
self.refresh_page()
def set_extra_http_headers(self, headers):
"""

Просмотреть файл

@ -9,12 +9,14 @@ class ContactSupportMessages:
"Firefox for Android": "Web browser for Android smartphones and tablets",
"Firefox for iOS": "Firefox for iPhone, iPad and iPod touch devices",
"Firefox for Enterprise": "Firefox Quantum for businesses",
"MDN Plus": "MDN Plus provides a custom experience for MDN supporters.",
"Mozilla VPN": "VPN for Windows 10, Android and iOS devices",
"Firefox Relay": "Service that lets you create aliases to hide your real email",
"Mozilla Monitor": "Stay informed and take back control of your exposed data",
"Pocket": "The webs most intriguing articles",
"MDN Plus": "MDN Plus provides a custom user experience for MDN supporters.",
"Mozilla VPN": "VPN for Windows 10, Mac, Linux, Android, and iOS devices",
"Firefox Relay": "Service that lets you create email masks to hide your real email "
"address",
"Mozilla Monitor": "Find out if your private information has been exposed in a known "
"data breach.",
"Pocket": "Discover and save stories for later.",
"Thunderbird": "Email software for Windows, Mac and Linux",
"Firefox Focus": "Automatic privacy browser and content blocker",
"Mozilla Account": "Mozilla account is the account system for Mozilla",
"Mozilla Account": "Privacy-first products for desktop and mobile"
}

Просмотреть файл

@ -2,7 +2,7 @@
"valid_firefox_question": {
"subject": "Test Question ",
"subject_updated": "Test Question Updated",
"topic_value": "bookmarks",
"topic_value": "Browse",
"question_body": "'''Lorem ipsum''' dolor ''sit amet'', consectetur [https://www.mediafax.ro adipiscing] elit, [[Stage test owl|sed]] do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt id aliquet risus feugiat in ante. Etiam non quam lacus suspendisse faucibus interdum posuere. Diam sollicitudin tempor id eu nisl nunc mi ipsum. Velit egestas dui id ornare arcu odio ut sem nulla. Risus nec feugiat in fermentum posuere urna nec tincidunt. Sed egestas egestas fringilla phasellus faucibus. Amet consectetur adipiscing elit duis tristique. Lorem mollis aliquam ut porttitor. Purus sit amet volutpat consequat mauris. Lobortis mattis aliquam faucibus purus in. Enim praesent elementum facilisis leo vel. Volutpat lacus laoreet non curabitur gravida arcu. Tempus iaculis urna id volutpat.",
"body_updated": "Updated body",
"simple_body_text": "Body content test",
@ -23,7 +23,7 @@
"troubleshooting_information": "Test Troubleshooting data",
"troubleshoot_product_and_os_versions": ["Test os", "Test product version"],
"products_aaq_url": {
"Firefox": "https://support.allizom.org/en-US/questions/new/desktop/form",
"Firefox": "https://support.allizom.org/en-US/questions/new/firefox/form",
"Firefox for Android": "https://support.allizom.org/en-US/questions/new/mobile/form",
"Firefox for iOS": "https://support.allizom.org/en-US/questions/new/ios/form",
"Firefox for Enterprise": "https://support.allizom.org/en-US/questions/new/firefox-enterprise/form",
@ -33,67 +33,78 @@
"Firefox Relay": "https://support.allizom.org/en-US/questions/new/relay/form",
"Pocket": "https://support.allizom.org/en-US/questions/new/pocket/form",
"Thunderbird": "https://support.allizom.org/en-US/questions/new/thunderbird/form",
"Firefox Focus": "https://support.allizom.org/en-US/questions/new/focus/form",
"Firefox Focus": "https://support.allizom.org/en-US/questions/new/focus-firefox/form",
"Mozilla Account": "https://support.allizom.org/en-US/questions/new/mozilla-account/form"
},
"product_without_aaq_url" : "https://support.allizom.org/en-US/kb/get-community-support?exit_aaq=1",
"aaq_topic_tags": {
"Firefox": {
"Install and update": "install-and-update",
"Protect your privacy": "protect-your-privacy",
"Customize settings and preferences": "customize-settings-and-preferences",
"Troubleshooting": "troubleshooting",
"Tips and tricks": "tips",
"Bookmarks": "bookmarks",
"Cookies": "cookies",
"Tabs": "tabs",
"Website breakages": "website-breakages",
"Firefox Sync": "sync",
"Other": "other",
"default_slug": "desktop"
"Accessibility": "accessibility",
"Accounts": "accounts",
"Backup, recovery, and sync": "backup-recovery-and-sync",
"Browse": "browse",
"Download and save": "download-and-save",
"Installation and updates": "installation-and-updates",
"Passwords and sign in": "passwords-and-sign-in",
"Performance and connectivity": "performance-and-connectivity",
"Privacy and security": "privacy-and-security",
"Search, tag, and share": "search-tag-and-share",
"Settings": "settings",
"default_slug": "firefox"
},
"Firefox for Android": {
"Install and update": "install-and-update",
"Protect your privacy": "protect-your-privacy",
"Customize settings and preferences": "customize-settings-and-preferences",
"Troubleshooting": "troubleshooting",
"Tips and tricks": "tips",
"Bookmarks": "bookmarks",
"Cookies": "cookies",
"Tabs": "tabs",
"Websites": "websites",
"Firefox Sync": "sync",
"Other": "other",
"Accessibility": "accessibility",
"Accounts": "accounts",
"Backup, recovery, and sync": "backup-recovery-and-sync",
"Browse": "browse",
"Download and save": "download-and-save",
"Installation and updates": "installation-and-updates",
"Passwords and sign in": "passwords-and-sign-in",
"Performance and connectivity": "performance-and-connectivity",
"Privacy and security": "privacy-and-security",
"Search, tag, and share": "search-tag-and-share",
"Settings": "settings",
"default_slug": "mobile"
},
"Firefox for iOS": {
"Install and update": "install-and-update",
"How to use Firefox for iOS": "how-to-use-firefox-ios",
"Troubleshooting": "troubleshooting",
"Sync": "sync",
"Bookmarks": "bookmarks",
"Tabs": "tabs",
"Protect your privacy": "protect-your-privacy",
"Accessibility": "accessibility",
"Accounts": "accounts",
"Backup, recovery, and sync": "backup-recovery-and-sync",
"Browse": "browse",
"Download and save": "download-and-save",
"Installation and updates": "installation-and-updates",
"Passwords and sign in": "passwords-and-sign-in",
"Performance and connectivity": "performance-and-connectivity",
"Privacy and security": "privacy-and-security",
"Search, tag, and share": "search-tag-and-share",
"Settings": "settings",
"default_slug": "ios"
},
"Firefox for Enterprise": {
"Install and update": [ "deployment", "install-and-update"],
"Install and manage add-ons": ["customization", "install-and-manage-add-ons"],
"Customize settings and preferences": "customize-settings-and-preferences",
"Accounts": "accounts",
"Installation and updates": "installation-and-updates",
"Privacy and security": "privacy-and-security",
"Settings": "settings",
"default_slug": "none"
},
"Thunderbird": {
"Install and update": "install-and-update",
"Protect your privacy": "protect-your-privacy",
"Customize settings and preferences": "customize-settings-and-preferences",
"Troubleshooting": "troubleshooting",
"Calendar": "calendar",
"Other": "other",
"Accessibility": "accessibility",
"Accounts": "accounts",
"Email and messaging": "email-and-messaging",
"Installation and updates": "installation-and-updates",
"Passwords and sign in": "passwords-and-sign-in",
"Performance and connectivity": "performance-and-connectivity",
"Privacy and security": "privacy-and-security",
"Search, tag, and share": "search-tag-and-share",
"Settings": "settings",
"default_slug": "none"
},
"Firefox Focus": {
"Firefox Focus for iOS": "Focus-ios",
"Firefox Focus for Android": "firefox-focus-android",
"Installation and updates": "installation-and-updates",
"Performance and connectivity": "performance-and-connectivity",
"Privacy and security": "privacy-and-security",
"Search, tag, and share": "search-tag-and-share",
"Settings": "settings",
"default_slug": "focus-firefox"
}
}

Просмотреть файл

@ -25,15 +25,15 @@
"Canned Responses"
],
"product_topics": {
"Firefox": "https://support.allizom.org/en-US/products/firefox/troubleshooting",
"Firefox for Android": "https://support.allizom.org/en-US/products/mobile/troubleshooting",
"Firefox for iOS": "https://support.allizom.org/en-US/products/ios/install-and-update",
"Firefox for Enterprise": "https://support.allizom.org/en-US/products/firefox-enterprise/install-and-update",
"Firefox": "https://support.allizom.org/en-US/products/firefox/browse",
"Firefox for Android": "https://support.allizom.org/en-US/products/mobile/browse",
"Firefox for iOS": "https://support.allizom.org/en-US/products/ios/browse",
"Firefox for Enterprise": "https://support.allizom.org/en-US/products/firefox-enterprise/installation-and-updates",
"MDN Plus": "https://support.allizom.org/en-US/products/mdn-plus/getting-started",
"Mozilla VPN": "https://support.allizom.org/en-US/products/firefox-private-network-vpn/accounts",
"Firefox Relay": "https://support.allizom.org/en-US/products/relay/technical",
"Pocket": "https://support.allizom.org/en-US/products/pocket/pocket-for-ios",
"Thunderbird": "https://support.allizom.org/en-US/products/thunderbird/protect-your-privacy",
"Thunderbird": "https://support.allizom.org/en-US/products/thunderbird/settings",
"Firefox Focus": "https://support.allizom.org/en-US/products/focus-firefox/Focus-ios",
"Mozilla Account": "https://support.allizom.org/en-US/products/mozilla-account/passwords-recovery"
},
@ -51,7 +51,7 @@
"Thunderbird": "https://support.allizom.org/en-US/products/thunderbird"
},
"product_solutions": {
"Firefox": "https://support.allizom.org/en-US/questions/new/desktop",
"Firefox": "https://support.allizom.org/en-US/questions/new/firefox",
"Firefox for Android": "https://support.allizom.org/en-US/questions/new/mobile",
"Firefox for iOS": "https://support.allizom.org/en-US/questions/new/ios",
"Firefox for Enterprise": "https://support.allizom.org/en-US/questions/new/firefox-enterprise",
@ -61,7 +61,7 @@
"Firefox Relay": "https://support.allizom.org/en-US/questions/new/relay",
"Pocket": "https://support.allizom.org/en-US/questions/new/pocket",
"Thunderbird": "https://support.allizom.org/en-US/questions/new/thunderbird",
"Firefox Focus": "https://support.allizom.org/en-US/questions/new/focus",
"Firefox Focus": "https://support.allizom.org/en-US/questions/new/focus-firefox",
"Mozilla Account": "https://support.allizom.org/en-US/questions/new/mozilla-account"
},
"dashboard_links": {

Просмотреть файл

@ -472,6 +472,7 @@ def test_premium_products_aaq(page: Page):
utilities.aaq_question_test_data['products_aaq_url'][premium_product]
)
utilities.wait_for_dom_to_load()
premium_form_link = utilities.get_page_url()
if premium_product == 'Mozilla VPN':
sumo_pages.aaq_flow.submit_an_aaq_question(
subject=utilities.aaq_question_test_data['premium_aaq_question']['subject'],
@ -484,6 +485,8 @@ def test_premium_products_aaq(page: Page):
body=utilities.aaq_question_test_data['premium_aaq_question']['body'],
is_premium=True
)
if utilities.get_page_url() == premium_form_link:
sumo_pages.aaq_form_page._click_aaq_form_submit_button()
with allure.step("Verifying that the correct success message is displayed"):
assert sumo_pages.aaq_form_page._get_premium_card_submission_message(

Просмотреть файл

@ -11,8 +11,7 @@ from playwright_tests.messages.ask_a_question_messages.contact_support_messages
ContactSupportMessages)
from playwright_tests.pages.sumo_pages import SumoPages
troubleshooting_topic_url = ("https://support.allizom.org/en-US/topics/customize-settings-and"
"-preferences")
troubleshooting_topic_url = "https://support.allizom.org/en-US/topics/browse"
# C2663958, C2663959
@ -20,11 +19,11 @@ troubleshooting_topic_url = ("https://support.allizom.org/en-US/topics/customize
def test_explore_by_topic_product_filter(page: Page):
sumo_pages = SumoPages(page)
utilities = Utilities(page)
with allure.step("Navigating to the /topics/ Customize settings and preferences page"):
with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)
for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Customize settings and preferences":
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
with allure.step("Verifying that the correct page header is displayed"):
assert topic == (sumo_pages.explore_by_topic_page
@ -37,10 +36,8 @@ def test_explore_by_topic_product_filter(page: Page):
sumo_pages.explore_by_topic_page._select_a_filter_by_product_option(
product.strip())
time.sleep(2)
# This currently fails due to https://github.com/mozilla/sumo/issues/1901.
# Uncommenting after the issue is fixed.
# if not sumo_pages.explore_by_topic_page._get_metadata_of_all_listed_articles():
# pytest.fail(f"There is no sublist for {product}")
if not sumo_pages.explore_by_topic_page._get_metadata_of_all_listed_articles():
pytest.fail(f"There is no sublist for {product}")
for sublist in (sumo_pages.explore_by_topic_page
._get_metadata_of_all_listed_articles()):
@ -58,11 +55,11 @@ def test_explore_by_topic_aaq_widget_text(page: Page):
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))
with allure.step("Navigating to the /topics/ Customize settings and preferences page"):
with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)
for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Customize settings and preferences":
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page._get_all_filter_by_product_options():
product = product.strip()
@ -96,12 +93,12 @@ def test_explore_by_topic_aaq_widget_redirect(page: Page):
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))
with allure.step("Navigating to the /topics/ Customize settings and preferences page"):
with allure.step("Navigating to the /topics/ Browse page"):
utilities.navigate_to_link(troubleshooting_topic_url)
for topic in sumo_pages.explore_by_topic_page._get_all_topics_side_navbar_options():
topic = topic.strip()
if topic != "Customize settings and preferences":
if topic != "Browse":
sumo_pages.explore_by_topic_page._click_on_a_topic_filter(topic)
for product in sumo_pages.explore_by_topic_page._get_all_filter_by_product_options():
product = product.strip()

Просмотреть файл

@ -54,7 +54,7 @@ def test_there_are_no_messages_here_text_is_displayed_when_no_messages_are_avail
def test_private_messages_can_be_sent_via_user_profiles(page: Page, is_firefox):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test1"
message_body = "Test " + utilities.generate_random_number(1, 1000)
user_two = utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_2"]
)
@ -138,7 +138,7 @@ def test_private_messages_can_be_sent_via_user_profiles(page: Page, is_firefox):
def test_private_message_can_be_sent_via_new_message_page(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test2"
message_body = "Test " + utilities.generate_random_number(1, 1000)
test_user = utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_4"]
)
@ -380,7 +380,7 @@ def test_new_message_field_validation(page: Page):
def test_new_message_cancel_button(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test3"
message_body = "Test " + utilities.generate_random_number(1, 1000)
user_two = utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_13"]
)
@ -526,7 +526,7 @@ def test_new_message_preview(page: Page):
def test_messages_can_be_selected_and_deleted(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test4"
message_body = "Test " + utilities.generate_random_number(1, 1000)
test_user = utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MESSAGE_6"]
)
@ -671,7 +671,7 @@ def test_group_messages_cannot_be_sent_by_non_staff_users(page: Page):
def test_staff_users_can_send_group_messages(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = 'Test5'
message_body = "Test " + utilities.generate_random_number(1, 1000)
with allure.step("Signing in with an admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts['TEST_ACCOUNT_MODERATOR']
@ -729,7 +729,7 @@ def test_staff_users_can_send_group_messages(page: Page):
def test_staff_users_can_send_messages_to_multiple_groups(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test6"
message_body = "Test " + utilities.generate_random_number(1, 1000)
with allure.step("Signing in with an admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts['TEST_ACCOUNT_MODERATOR']
@ -779,7 +779,7 @@ def test_staff_users_can_send_messages_to_both_groups_and_user(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
with allure.step("Signing in with an admin account"):
message_body = "Test7"
message_body = "Test " + utilities.generate_random_number(1, 1000)
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts['TEST_ACCOUNT_MODERATOR']
))
@ -831,7 +831,7 @@ def test_staff_users_can_send_messages_to_both_groups_and_user(page: Page):
def test_removed_group_users_do_not_receive_group_messages(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
message_body = "Test8"
message_body = "Test " + utilities.generate_random_number(1, 1000)
with allure.step("Signing in with a staff account and removing a user from the targeted "
"group"):
utilities.start_existing_session(utilities.username_extraction_from_email(
@ -920,7 +920,7 @@ def test_clear_inbox_and_outbox(page: Page):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts[user]
))
sumo_pages.top_navbar._click_on_inbox_option()
inbox_and_outbox_deletion(page)
utilities.delete_cookies()
@ -933,7 +933,6 @@ def test_clear_inbox_and_outbox(page: Page):
def inbox_and_outbox_deletion(page: Page):
sumo_pages = SumoPages(page)
sumo_pages.top_navbar._click_on_inbox_option()
if sumo_pages.inbox_page._are_inbox_messages_displayed():
sumo_pages.inbox_page._delete_all_inbox_messages_via_delete_selected_button()

Просмотреть файл

@ -151,7 +151,6 @@ def test_correct_messages_is_displayed_if_user_has_no_posted_questions(page: Pag
utilities.delete_cookies()
sumo_pages.top_navbar._click_on_signin_signup_button()
sumo_pages.auth_flow_page.login_with_existing_session()
sumo_pages.top_navbar._click_on_view_profile_option()
sumo_pages.user_navbar._click_on_my_questions_option()
assert (
sumo_pages.my_questions_page._get_text_of_no_question_message()