44from selenium .webdriver import Firefox
55
66from modules .browser_object import Navigation
7- from modules .browser_object_tabbar import TabBar
87from modules .page_object import AboutPrefs , GenericPage
98
109
@@ -13,9 +12,7 @@ def test_case():
1312 return "1756748"
1413
1514
16- # Constants
1715DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
18- # WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
1916
2017
2118@pytest .fixture ()
@@ -24,44 +21,68 @@ def delete_files_regex_string():
2421
2522
2623def 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- """
3024 if sys_platform == "Darwin" :
3125 return "TextEdit" if opt_ci else "Pages"
32- # Linux/Windows
3326 return "LibreOffice Writer"
3427
3528
3629@pytest .mark .noxvfb
37- # @pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows Github Actions")
3830def test_mime_type_doc (driver : Firefox , sys_platform : str , opt_ci : bool , delete_files ):
3931 """
4032 C1756748 - Verify that downloading a .doc file adds a new MIME type entry
4133 and the correct default application is assigned.
4234 """
43- # Instantiate objects
35+ print (f"\n { '=' * 60 } " )
36+ print (f"Platform: { sys_platform } , CI: { opt_ci } " )
37+ print (f"{ '=' * 60 } " )
38+
39+ if sys_platform == "Windows" :
40+ print ("\n --- Checking for LibreOffice ---" )
41+ result = subprocess .run (
42+ ["where" , "soffice.exe" ], capture_output = True , text = True
43+ )
44+ print (f"LibreOffice installed: { result .returncode == 0 } " )
45+ if result .returncode == 0 :
46+ print (f"Location: { result .stdout .strip ()} " )
47+
4448 page = GenericPage (driver , url = DOC_LINK )
4549 nav = Navigation (driver )
4650 about_prefs = AboutPrefs (driver , category = "general" )
47- tabs = TabBar (driver )
4851
49- # Open the test page with the .doc download link
52+ print ( " \n --- Opening page and downloading ---" )
5053 page .open ()
5154 page .click_on ("sample-doc-download" )
5255
53- # Download the file and set 'Always Open Similar Files'
5456 nav .set_always_open_similar_files ()
5557
56- # Verify the MIME type entry exists and default app matches expectation
57- tabs .new_tab_by_button ()
58- tabs .switch_to_new_tab ()
58+ print ("\n --- Opening about:preferences ---" )
5959 about_prefs .open ()
60+
61+ print ("\n --- Checking if MIME type exists ---" )
62+ try :
63+ exists = about_prefs .element_exists (
64+ "mime-type-item" , labels = ["application/msword" ]
65+ )
66+ print (f"MIME type exists: { exists } " )
67+ except Exception as e :
68+ print (f"Error checking existence: { e } " )
69+ exists = False
70+
71+ if not exists :
72+ print ("\n !!! MIME TYPE NOT FOUND !!!" )
73+ driver .save_screenshot ("artifacts/debug_no_mime.png" )
74+ pytest .fail ("MIME type entry was not created" )
75+
76+ print ("\n --- Getting app name ---" )
6077 app_name = about_prefs .get_app_name_for_mime_type ("application/msword" )
61- assert app_name == expected_app_name (sys_platform , opt_ci )
78+ expected = expected_app_name (sys_platform , opt_ci )
79+
80+ print (f"\n Result: '{ app_name } ' vs Expected: '{ expected } '" )
81+ assert app_name == expected , f"Mismatch: got '{ app_name } ', expected '{ expected } '"
82+ print ("✓ TEST PASSED" )
6283
63- # Kill LibreOffice before cleanup to prevent file lock
6484 if sys_platform == "Windows" :
85+ print ("\n --- Cleaning up ---" )
6586 subprocess .run (
6687 ["taskkill" , "/F" , "/IM" , "soffice.bin" ], capture_output = True , check = False
6788 )
0 commit comments