Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/browser_object_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ def get_download_button(self) -> WebElement:
def click_download_button(self) -> BasePage:
self.get_download_button().click()
return self
@BasePage.context_chrome
def set_always_open_similar_files(self) -> BasePage:
"""
From the downloads panel, right-click the most recent download and set 'Always Open Similar Files'.
"""
downloads_button = self.get_download_button()
downloads_button.click()

# Locate the latest downloaded file in the panel, open context menu and choose 'Always Open Similar Files'
download_item = self.get_element("download-panel-item")
self.context_click(download_item)
self.context_menu.get_element("context-menu-always-open-similar-files").click()

return self

@BasePage.context_chrome
def wait_for_download_animation_finish(
Expand Down
19 changes: 19 additions & 0 deletions modules/page_object_prefs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import json
import re
from time import sleep
from typing import List
Expand Down Expand Up @@ -612,6 +613,24 @@ def click_popup_panel_button(self, field: str) -> BasePage:
self.get_element("panel-popup-button", labels=[field]).click()
return self

def get_app_name_for_mime_type(self, mime_type: str) -> str:
"""
Return the application name associated with a given MIME type in about:preferences.
Argument:
mime_type: the MIME type to look up (e.g., "application/msword").
"""
# Locate the row for the given MIME type
mime_type_item = self.get_element("mime-type-item", labels=[mime_type])

# Find the description element that contains application info
action_description = self.get_element(
"mime-type-item-description", parent_element=mime_type_item
)

# Parse the JSON data-l10n-args attribute and extract app name
mime_type_data = json.loads(action_description.get_attribute("data-l10n-args"))
return mime_type_data["app-name"]


class AboutAddons(BasePage):
"""
Expand Down
54 changes: 24 additions & 30 deletions tests/downloads/test_add_mime_type_doc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json
import sys
from os import environ

import pytest
from selenium.webdriver import Firefox

from modules.browser_object import ContextMenu, Navigation
from modules.browser_object import Navigation
from modules.page_object import AboutPrefs, GenericPage


Expand All @@ -14,8 +13,8 @@ def test_case():
return "1756748"


# Constants
DOC_LINK = "https://sapphire-hendrika-5.tiiny.site/"

WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")


Expand All @@ -24,41 +23,36 @@ def delete_files_regex_string():
return r"sample.*\.doc"


def expected_app_name(sys_platform: str, opt_ci: bool) -> str:
"""
Decide which default application should be used to open .doc files, based on OS and CI environment
"""
if sys_platform == "Darwin":
return "TextEdit" if opt_ci else "Pages"
# Linux/Windows use LibreOffice
return "LibreOffice Writer"


@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows Github Actions")
@pytest.mark.noxvfb
def test_mime_type_doc(driver: Firefox, sys_platform: str, opt_ci: bool, delete_files):
"""
C1756748: Verify the user can add the .doc type
C1756748 - Verify that downloading a .doc file adds a new MIME type entry
and the correct default application is assigned.
"""
doc_page = GenericPage(driver, url=DOC_LINK).open()
# Instantiate objects
page = GenericPage(driver, url=DOC_LINK)
nav = Navigation(driver)
context_menu = ContextMenu(driver)
about_prefs = AboutPrefs(driver, category="general")
doc_page.get_element("sample-doc-download").click()

downloads_button = nav.get_download_button()
# Open the test page with the .doc download link
page.open()
page.click_on("sample-doc-download")

with driver.context(driver.CONTEXT_CHROME):
downloads_button.click()
download_item = nav.get_element("download-panel-item")
nav.context_click(download_item)
context_menu.get_element("context-menu-always-open-similar-files").click()
# Download the file and set 'Always Open Similar Files'
nav.set_always_open_similar_files()

# Verify the MIME type entry exists and default app matches expectation
about_prefs.open()
about_prefs.element_exists("mime-type-item", labels=["application/msword"])

mime_type_item = about_prefs.get_element(
"mime-type-item", labels=["application/msword"]
)
action_description_item = about_prefs.get_element(
"mime-type-item-description", parent_element=mime_type_item
)

mime_type_data = json.loads(action_description_item.get_attribute("data-l10n-args"))
if sys_platform == "Darwin":
if opt_ci:
assert mime_type_data["app-name"] == "TextEdit"
else:
assert mime_type_data["app-name"] == "Pages"
else:
assert mime_type_data["app-name"] == "LibreOffice Writer"
app_name = about_prefs.get_app_name_for_mime_type("application/msword")
assert app_name == expected_app_name(sys_platform, opt_ci)
Loading