Skip to content

Commit 57383ee

Browse files
committed
Refactored and win stabilisation
1 parent 700444c commit 57383ee

File tree

8 files changed

+70
-38
lines changed

8 files changed

+70
-38
lines changed

modules/browser_object_navigation.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,20 @@ def click_download_button(self) -> BasePage:
245245
self.get_download_button().click()
246246
return self
247247

248+
@BasePage.context_chrome
249+
def set_always_open_similar_files(self) -> BasePage:
250+
"""
251+
From the downloads panel, right-click the most recent download and set 'Always Open Similar Files'.
252+
"""
253+
downloads_button = self.get_download_button()
254+
downloads_button.click()
255+
256+
# Locate the latest downloaded file in the panel, open context menu and choose 'Always Open Similar Files'
257+
download_item = self.get_element("download-panel-item")
258+
self.context_click(download_item)
259+
self.context_menu.get_element("context-menu-always-open-similar-files").click()
260+
return self
261+
248262
@BasePage.context_chrome
249263
def wait_for_download_animation_finish(
250264
self, downloads_button: WebElement

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, Literal
@@ -638,6 +639,24 @@ def click_popup_panel_button(self, field: str) -> BasePage:
638639
self.get_element("panel-popup-button", labels=[field]).click()
639640
return self
640641

642+
def get_app_name_for_mime_type(self, mime_type: str) -> str:
643+
"""
644+
Return the application name associated with a given MIME type in about:preferences.
645+
Argument:
646+
mime_type: the MIME type to look up (e.g., "application/msword").
647+
"""
648+
# Locate the row for the given MIME type
649+
mime_type_item = self.get_element("mime-type-item", labels=[mime_type])
650+
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+
)
655+
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+
641660

642661
class AboutAddons(BasePage):
643662
"""
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import json
2-
import sys
3-
from os import environ
1+
import subprocess
42

53
import pytest
64
from selenium.webdriver import Firefox
75

8-
from modules.browser_object import ContextMenu, Navigation
6+
from modules.browser_object import Navigation
97
from modules.page_object import AboutPrefs, GenericPage
108

119

@@ -14,51 +12,53 @@ def test_case():
1412
return "1756748"
1513

1614

15+
# Constants
1716
DOC_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()
2320
def 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
2935
def 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+
)

tests/tabs/test_active_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from modules.browser_object import TabBar
55

6-
76
NUM_TABS = 5
87

98

tests/tabs/test_navigation_multiple_tabs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
2+
23
import pytest
34
from selenium.webdriver import Firefox
5+
46
from modules.browser_object import TabBar
57

68
NUM_TABS = 20

tests/tabs/test_open_bookmark_in_new_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def test_case():
1818

1919

2020
def test_open_bookmark_in_new_tab(driver: Firefox):
21-
2221
"""
2322
C134460: Verify that New Tabs can be opened by right clicking and selecting new tab from the bookmarks.
2423
"""

tests/tabs/test_open_new_tab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from modules.browser_object import TabBar
66

7-
87
URL = "about:robots"
98
EXPECTED_TEXT = "Firefox"
109

tests/tabs/test_open_new_tab_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.support import expected_conditions as EC
4-
from modules.browser_object import TabBar
54

5+
from modules.browser_object import TabBar
66

77
URL = "about:robots"
88
EXPECTED_TEXT = "Firefox"

0 commit comments

Comments
 (0)