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
@@ -14,8 +13,8 @@ def test_case():
1413 return "1756748"
1514
1615
16+ # Constants
1717DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
18-
1918WIN_GHA = environ .get ("GITHUB_ACTIONS" ) == "true" and sys .platform .startswith ("win" )
2019
2120
@@ -24,41 +23,36 @@ def delete_files_regex_string():
2423 return r"sample.*\.doc"
2524
2625
26+ def expected_app_name (sys_platform : str , opt_ci : bool ) -> str :
27+ """
28+ Decide which default application should be used to open .doc files, based on OS and CI environment
29+ """
30+ if sys_platform == "Darwin" :
31+ return "TextEdit" if opt_ci else "Pages"
32+ # Linux/Windows use LibreOffice
33+ return "LibreOffice Writer"
34+
35+
2736@pytest .mark .skipif (WIN_GHA , reason = "Test unstable in Windows Github Actions" )
2837@pytest .mark .noxvfb
2938def test_mime_type_doc (driver : Firefox , sys_platform : str , opt_ci : bool , delete_files ):
3039 """
31- C1756748: Verify the user can add the .doc type
40+ C1756748 - Verify that downloading a .doc file adds a new MIME type entry
41+ and the correct default application is assigned.
3242 """
33- doc_page = GenericPage (driver , url = DOC_LINK ).open ()
43+ # Instantiate objects
44+ page = GenericPage (driver , url = DOC_LINK )
3445 nav = Navigation (driver )
35- context_menu = ContextMenu (driver )
3646 about_prefs = AboutPrefs (driver , category = "general" )
37- doc_page .get_element ("sample-doc-download" ).click ()
3847
39- downloads_button = nav .get_download_button ()
48+ # Open the test page with the .doc download link
49+ page .open ()
50+ page .click_on ("sample-doc-download" )
4051
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 ()
52+ # Download the file and set 'Always Open Similar Files'
53+ nav .set_always_open_similar_files ()
4654
55+ # Verify the MIME type entry exists and default app matches expectation
4756 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"
57+ app_name = about_prefs .get_app_name_for_mime_type ("application/msword" )
58+ assert app_name == expected_app_name (sys_platform , opt_ci )
0 commit comments