1- import json
2- import sys
3- from os import environ
1+ import subprocess
42
53import pytest
64from selenium .webdriver import Firefox
75
8- from modules .browser_object import ContextMenu , Navigation
6+ from modules .browser_object import Navigation
97from modules .page_object import AboutPrefs , GenericPage
108
119
@@ -14,51 +12,53 @@ def test_case():
1412 return "1756748"
1513
1614
15+ # Constants
1716DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
1817
19- WIN_GHA = environ .get ("GITHUB_ACTIONS" ) == "true" and sys .platform .startswith ("win" )
20-
2118
2219@pytest .fixture ()
2320def delete_files_regex_string ():
2421 return r"sample.*\.doc"
2522
2623
27- @pytest .mark .skipif (WIN_GHA , reason = "Test unstable in Windows Github Actions" )
24+ def expected_app_name (sys_platform : str , opt_ci : bool ) -> str :
25+ """
26+ Decide which default application should be used to open .doc files, based on OS and CI environment
27+ """
28+ if sys_platform == "Darwin" :
29+ return "TextEdit" if opt_ci else "Pages"
30+ # Linux/Windows
31+ return "LibreOffice Writer"
32+
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+ # Instantiate objects
41+ page = GenericPage (driver , url = DOC_LINK )
3442 nav = Navigation (driver )
35- context_menu = ContextMenu (driver )
3643 about_prefs = AboutPrefs (driver , category = "general" )
37- doc_page .get_element ("sample-doc-download" ).click ()
3844
39- downloads_button = nav .get_download_button ()
45+ # Open the test page with the .doc download link
46+ page .open ()
47+ page .click_on ("sample-doc-download" )
4048
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 ()
49+ # Download the file and set 'Always Open Similar Files'
50+ nav .set_always_open_similar_files ()
4651
52+ # Verify the MIME type entry exists and default app matches expectation
4753 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"
54+ app_name = about_prefs .get_app_name_for_mime_type ("application/msword" )
55+ assert app_name == expected_app_name (sys_platform , opt_ci )
56+
57+ # Kill LibreOffice before cleanup to prevent file lock
58+ if sys_platform == "Windows" :
59+ subprocess .run (
60+ ["taskkill" , "/F" , "/IM" , "soffice.bin" ], capture_output = True , check = False
61+ )
62+ subprocess .run (
63+ ["taskkill" , "/F" , "/IM" , "soffice.exe" ], capture_output = True , check = False
64+ )
0 commit comments