Skip to content

Commit 58d6e35

Browse files
committed
Add refactored test 1756748
1 parent c56fdd2 commit 58d6e35

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

modules/browser_object_navigation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ def get_download_button(self) -> WebElement:
243243
def click_download_button(self) -> BasePage:
244244
self.get_download_button().click()
245245
return self
246+
@BasePage.context_chrome
247+
def set_always_open_similar_files(self) -> BasePage:
248+
"""
249+
From the downloads panel, right-click the most recent download and set 'Always Open Similar Files'.
250+
"""
251+
downloads_button = self.get_download_button()
252+
downloads_button.click()
253+
254+
# Locate the latest downloaded file in the panel, open context menu and choose 'Always Open Similar Files'
255+
download_item = self.get_element("download-panel-item")
256+
self.context_click(download_item)
257+
self.context_menu.get_element("context-menu-always-open-similar-files").click()
258+
259+
return self
246260

247261
@BasePage.context_chrome
248262
def wait_for_download_animation_finish(

modules/page_object_prefs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import json
23
import re
34
from time import sleep
45
from typing import List
@@ -612,6 +613,24 @@ def click_popup_panel_button(self, field: str) -> BasePage:
612613
self.get_element("panel-popup-button", labels=[field]).click()
613614
return self
614615

616+
def get_app_name_for_mime_type(self, mime_type: str) -> str:
617+
"""
618+
Return the application name associated with a given MIME type in about:preferences.
619+
Argument:
620+
mime_type: the MIME type to look up (e.g., "application/msword").
621+
"""
622+
# Locate the row for the given MIME type
623+
mime_type_item = self.get_element("mime-type-item", labels=[mime_type])
624+
625+
# Find the description element that contains application info
626+
action_description = self.get_element(
627+
"mime-type-item-description", parent_element=mime_type_item
628+
)
629+
630+
# Parse the JSON data-l10n-args attribute and extract app name
631+
mime_type_data = json.loads(action_description.get_attribute("data-l10n-args"))
632+
return mime_type_data["app-name"]
633+
615634

616635
class AboutAddons(BasePage):
617636
"""
Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import json
21
import sys
32
from os import environ
43

54
import pytest
65
from selenium.webdriver import Firefox
76

8-
from modules.browser_object import ContextMenu, Navigation
7+
from modules.browser_object import Navigation
98
from modules.page_object import AboutPrefs, GenericPage
109

1110

@@ -14,8 +13,8 @@ def test_case():
1413
return "1756748"
1514

1615

16+
# Constants
1717
DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"
18-
1918
WIN_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
2938
def 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

Comments
 (0)