diff --git a/modules/page_object_prefs.py b/modules/page_object_prefs.py index af615fcf8..9f0528e16 100644 --- a/modules/page_object_prefs.py +++ b/modules/page_object_prefs.py @@ -1,9 +1,9 @@ import datetime +import json import re from time import sleep from typing import List, Literal -from rich import json from selenium.webdriver import Firefox from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys @@ -639,6 +639,7 @@ def click_popup_panel_button(self, field: str) -> BasePage: self.get_element("panel-popup-button", labels=[field]).click() return self + @BasePage.context_content def get_app_name_for_mime_type(self, mime_type: str) -> str: """ Return the application name associated with a given MIME type in about:preferences. diff --git a/tests/downloads/test_add_mime_type_doc.py b/tests/downloads/test_add_mime_type_doc.py index 4b30e5a49..96492fd46 100644 --- a/tests/downloads/test_add_mime_type_doc.py +++ b/tests/downloads/test_add_mime_type_doc.py @@ -1,11 +1,10 @@ -import json import sys from os import environ import pytest from selenium.webdriver import Firefox -from modules.browser_object import ContextMenu, Navigation +from modules.browser_object import Navigation from modules.page_object import AboutPrefs, GenericPage @@ -15,7 +14,6 @@ def test_case(): DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/" - WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win") @@ -24,41 +22,35 @@ def delete_files_regex_string(): return r"sample.*\.doc" -@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows Github Actions") +def expected_app_name(sys_platform: str, opt_ci: bool) -> str: + if sys_platform == "Darwin": + return "TextEdit" if opt_ci else "Pages" + return "LibreOffice Writer" + + +@pytest.mark.skipif( + WIN_GHA, reason="Most runners don’t have a .doc handler registered on Windows" +) @pytest.mark.noxvfb def test_mime_type_doc(driver: Firefox, sys_platform: str, opt_ci: bool, delete_files): """ - C1756748: Verify the user can add the .doc type + C1756748 - Verify that downloading a .doc file adds a new MIME type entry + and the correct default application is assigned. """ - doc_page = GenericPage(driver, url=DOC_LINK).open() + + # Instantiate objects + page = GenericPage(driver, url=DOC_LINK) nav = Navigation(driver) - context_menu = ContextMenu(driver) about_prefs = AboutPrefs(driver, category="general") - doc_page.get_element("sample-doc-download").click() - downloads_button = nav.get_download_button() + # Open the test page with the .doc download link + page.open() + page.click_on("sample-doc-download") - with driver.context(driver.CONTEXT_CHROME): - downloads_button.click() - download_item = nav.get_element("download-panel-item") - nav.context_click(download_item) - context_menu.get_element("context-menu-always-open-similar-files").click() + # Download the file and set 'Always Open Similar Files' + nav.set_always_open_similar_files() + # Verify the MIME type entry exists and default app matches expectation about_prefs.open() - about_prefs.element_exists("mime-type-item", labels=["application/msword"]) - - mime_type_item = about_prefs.get_element( - "mime-type-item", labels=["application/msword"] - ) - action_description_item = about_prefs.get_element( - "mime-type-item-description", parent_element=mime_type_item - ) - - mime_type_data = json.loads(action_description_item.get_attribute("data-l10n-args")) - if sys_platform == "Darwin": - if opt_ci: - assert mime_type_data["app-name"] == "TextEdit" - else: - assert mime_type_data["app-name"] == "Pages" - else: - assert mime_type_data["app-name"] == "LibreOffice Writer" + app_name = about_prefs.get_app_name_for_mime_type("application/msword") + assert app_name == expected_app_name(sys_platform, opt_ci)