1
- import json
2
1
import sys
3
2
from os import environ
4
3
5
4
import pytest
6
5
from selenium .webdriver import Firefox
7
6
8
- from modules .browser_object import ContextMenu , Navigation
7
+ from modules .browser_object import Navigation
9
8
from modules .page_object import AboutPrefs , GenericPage
10
9
11
10
@@ -14,8 +13,8 @@ def test_case():
14
13
return "1756748"
15
14
16
15
16
+ # Constants
17
17
DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
18
-
19
18
WIN_GHA = environ .get ("GITHUB_ACTIONS" ) == "true" and sys .platform .startswith ("win" )
20
19
21
20
@@ -24,41 +23,36 @@ def delete_files_regex_string():
24
23
return r"sample.*\.doc"
25
24
26
25
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
+
27
36
@pytest .mark .skipif (WIN_GHA , reason = "Test unstable in Windows Github Actions" )
28
37
@pytest .mark .noxvfb
29
38
def test_mime_type_doc (driver : Firefox , sys_platform : str , opt_ci : bool , delete_files ):
30
39
"""
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.
32
42
"""
33
- doc_page = GenericPage (driver , url = DOC_LINK ).open ()
43
+ # Instantiate objects
44
+ page = GenericPage (driver , url = DOC_LINK )
34
45
nav = Navigation (driver )
35
- context_menu = ContextMenu (driver )
36
46
about_prefs = AboutPrefs (driver , category = "general" )
37
- doc_page .get_element ("sample-doc-download" ).click ()
38
47
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" )
40
51
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 ()
46
54
55
+ # Verify the MIME type entry exists and default app matches expectation
47
56
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