Skip to content

Commit 3c41248

Browse files
committed
Debugging
1 parent 159363a commit 3c41248

File tree

3 files changed

+83
-27
lines changed

3 files changed

+83
-27
lines changed

modules/browser_object_navigation.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,24 @@ def set_always_open_similar_files(self) -> BasePage:
250250
"""
251251
From the downloads panel, right-click the most recent download and set 'Always Open Similar Files'.
252252
"""
253+
print("\n[DEBUG] Starting set_always_open_similar_files")
254+
253255
downloads_button = self.get_download_button()
256+
print("[DEBUG] Got downloads button")
254257
downloads_button.click()
258+
print("[DEBUG] Clicked downloads button")
255259

256-
# Locate the latest downloaded file in the panel, open context menu and choose 'Always Open Similar Files'
257260
download_item = self.get_element("download-panel-item")
261+
print(
262+
f"[DEBUG] Got download item: {download_item.get_attribute('outerHTML')[:200]}"
263+
)
264+
258265
self.context_click(download_item)
266+
print("[DEBUG] Context clicked download item")
267+
259268
self.context_menu.get_element("context-menu-always-open-similar-files").click()
269+
print("[DEBUG] Clicked 'Always Open Similar Files'")
270+
260271
return self
261272

262273
@BasePage.context_chrome

modules/page_object_prefs.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,41 @@ def get_app_name_for_mime_type(self, mime_type: str) -> str:
645645
Argument:
646646
mime_type: the MIME type to look up (e.g., "application/msword").
647647
"""
648-
# Locate the row for the given MIME type
649-
mime_type_item = self.get_element("mime-type-item", labels=[mime_type])
648+
print(f"\n[DEBUG] Looking for MIME type: {mime_type}")
650649

651-
# Find the description element that contains application info
652-
action_description = self.get_element(
653-
"mime-type-item-description", parent_element=mime_type_item
654-
)
650+
try:
651+
mime_type_item = self.get_element("mime-type-item", labels=[mime_type])
652+
print(
653+
f"[DEBUG] Found MIME type item: {mime_type_item.get_attribute('outerHTML')[:300]}"
654+
)
655+
except Exception as e:
656+
print(f"[DEBUG] Failed to find MIME type item: {e}")
657+
raise
655658

656-
# Parse the JSON data-l10n-args attribute and extract app name
657-
mime_type_data = json.loads(action_description.get_attribute("data-l10n-args"))
658-
return mime_type_data["app-name"]
659+
try:
660+
action_description = self.get_element(
661+
"mime-type-item-description", parent_element=mime_type_item
662+
)
663+
print(
664+
f"[DEBUG] Found action description: {action_description.get_attribute('outerHTML')[:300]}"
665+
)
666+
except Exception as e:
667+
print(f"[DEBUG] Failed to find action description: {e}")
668+
raise
669+
670+
try:
671+
data_attr = action_description.get_attribute("data-l10n-args")
672+
print(f"[DEBUG] data-l10n-args: {data_attr}")
673+
674+
mime_type_data = json.loads(data_attr)
675+
print(f"[DEBUG] Parsed JSON: {mime_type_data}")
676+
677+
app_name = mime_type_data["app-name"]
678+
print(f"[DEBUG] Extracted app-name: {app_name}")
679+
return app_name
680+
except Exception as e:
681+
print(f"[DEBUG] Failed to parse app name: {e}")
682+
raise
659683

660684

661685
class AboutAddons(BasePage):

tests/downloads/test_add_mime_type_doc.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from selenium.webdriver import Firefox
55

66
from modules.browser_object import Navigation
7-
from modules.browser_object_tabbar import TabBar
87
from modules.page_object import AboutPrefs, GenericPage
98

109

@@ -13,9 +12,7 @@ def test_case():
1312
return "1756748"
1413

1514

16-
# Constants
1715
DOC_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

2623
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-
"""
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")
3830
def 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"\nResult: '{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

Comments
 (0)