1- import json
21import sys
32from os import environ
43
54import pytest
65from selenium .webdriver import Firefox
76
8- from modules .browser_object import ContextMenu , Navigation
7+ from modules .browser_object import Navigation
98from modules .page_object import AboutPrefs , GenericPage
109
1110
@@ -15,7 +14,6 @@ def test_case():
1514
1615
1716DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
18-
1917WIN_GHA = environ .get ("GITHUB_ACTIONS" ) == "true" and sys .platform .startswith ("win" )
2018
2119
@@ -24,41 +22,35 @@ def delete_files_regex_string():
2422 return r"sample.*\.doc"
2523
2624
27- @pytest .mark .skipif (WIN_GHA , reason = "Test unstable in Windows Github Actions" )
25+ def expected_app_name (sys_platform : str , opt_ci : bool ) -> str :
26+ if sys_platform == "Darwin" :
27+ return "TextEdit" if opt_ci else "Pages"
28+ return "LibreOffice Writer"
29+
30+
31+ @pytest .mark .skipif (
32+ WIN_GHA , reason = "Most runners don’t have a .doc handler registered on Windows"
33+ )
2834@pytest .mark .noxvfb
2935def test_mime_type_doc (driver : Firefox , sys_platform : str , opt_ci : bool , delete_files ):
3036 """
31- C1756748: Verify the user can add the .doc type
37+ C1756748 - Verify that downloading a .doc file adds a new MIME type entry
38+ and the correct default application is assigned.
3239 """
33- doc_page = GenericPage (driver , url = DOC_LINK ).open ()
40+
41+ # Instantiate objects
42+ page = GenericPage (driver , url = DOC_LINK )
3443 nav = Navigation (driver )
35- context_menu = ContextMenu (driver )
3644 about_prefs = AboutPrefs (driver , category = "general" )
37- doc_page .get_element ("sample-doc-download" ).click ()
3845
39- downloads_button = nav .get_download_button ()
46+ # Open the test page with the .doc download link
47+ page .open ()
48+ page .click_on ("sample-doc-download" )
4049
41- with driver .context (driver .CONTEXT_CHROME ):
42- downloads_button .click ()
43- download_item = nav .get_element ("download-panel-item" )
44- nav .context_click (download_item )
45- context_menu .get_element ("context-menu-always-open-similar-files" ).click ()
50+ # Download the file and set 'Always Open Similar Files'
51+ nav .set_always_open_similar_files ()
4652
53+ # Verify the MIME type entry exists and default app matches expectation
4754 about_prefs .open ()
48- about_prefs .element_exists ("mime-type-item" , labels = ["application/msword" ])
49-
50- mime_type_item = about_prefs .get_element (
51- "mime-type-item" , labels = ["application/msword" ]
52- )
53- action_description_item = about_prefs .get_element (
54- "mime-type-item-description" , parent_element = mime_type_item
55- )
56-
57- mime_type_data = json .loads (action_description_item .get_attribute ("data-l10n-args" ))
58- if sys_platform == "Darwin" :
59- if opt_ci :
60- assert mime_type_data ["app-name" ] == "TextEdit"
61- else :
62- assert mime_type_data ["app-name" ] == "Pages"
63- else :
64- assert mime_type_data ["app-name" ] == "LibreOffice Writer"
55+ app_name = about_prefs .get_app_name_for_mime_type ("application/msword" )
56+ assert app_name == expected_app_name (sys_platform , opt_ci )
0 commit comments