diff --git a/modules/browser_object_navigation.py b/modules/browser_object_navigation.py index ad0c64467..b64aad288 100644 --- a/modules/browser_object_navigation.py +++ b/modules/browser_object_navigation.py @@ -1,4 +1,5 @@ import logging +from typing import Literal from selenium.common.exceptions import TimeoutException from selenium.webdriver import ActionChains, Firefox @@ -658,3 +659,43 @@ def expect_bookmarks_toolbar_visibility(self, expected: bool) -> None: self.expect_element_attribute_contains( self.bookmarks_toolbar, "collapsed", expected_value ) + + # + def set_site_autoplay_permission( + self, + settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"], + ) -> BasePage: + """ + Open the Site audio-video permission panel and set a specific autoplay setting. + + Arguments: + settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video, + "allow-audio-only" → Allow Audio but block Video + """ + self.click_on("autoplay-icon-blocked") + + if settings == "allow-audio-video": + self.element_clickable("permission-popup-audio-blocked") + self.click_on("permission-popup-audio-blocked") + self.click_and_hide_menu("allow-audio-video-menuitem") + + elif settings == "block-audio-video": + self.element_clickable("permission-popup-audio-video-allowed") + self.click_and_hide_menu("block-audio-video-menuitem") + + elif settings == "allow-audio-only": + self.element_clickable("permission-popup-audio-video-allowed") + self.click_and_hide_menu("allow-audio-only-menuitem") + return self + + def verify_autoplay_state(self, expected: Literal["allow", "block"]) -> None: + """Verify the current state of the autoplay permission panel and icon. + Arguments: + expected: "allow" → Allow Audio and Video, "block" → Block Audio and Video + """ + if expected == "allow": + self.element_visible("permission-popup-audio-video-allowed") + self.element_not_visible("autoplay-icon-blocked") + else: + self.element_visible("permission-popup-audio-video-blocked") + self.element_visible("autoplay-icon-blocked") diff --git a/modules/browser_object_tabbar.py b/modules/browser_object_tabbar.py index 8668c033e..370be901c 100644 --- a/modules/browser_object_tabbar.py +++ b/modules/browser_object_tabbar.py @@ -136,10 +136,13 @@ def get_tab_title(self, tab_element: WebElement) -> str: tab_label = tab_element.find_element(*self.get_selector("tab-title")) return tab_label.text + @BasePage.context_chrome def expect_tab_sound_status( self, identifier: Union[str, int], status: MediaStatus ) -> BasePage: - """Check to see if the tab has an expected MediaStatus""" + """ + Check to see if the tab has an expected MediaStatus + """ tab = self.get_tab(identifier) self.wait.until(lambda _: tab.get_attribute(status) is not None) return self diff --git a/modules/data/navigation.components.json b/modules/data/navigation.components.json index a46b111bd..33108ce28 100644 --- a/modules/data/navigation.components.json +++ b/modules/data/navigation.components.json @@ -501,12 +501,6 @@ "groups": [] }, - "autoplay-permission": { - "selectorData": "blocked-permissions-container", - "strategy": "id", - "groups": [] - }, - "permissions-location-icon": { "selectorData": "permissions-granted-icon", "strategy": "id", diff --git a/modules/page_object_prefs.py b/modules/page_object_prefs.py index 465d76b04..db11765ca 100644 --- a/modules/page_object_prefs.py +++ b/modules/page_object_prefs.py @@ -1,7 +1,7 @@ import datetime import re from time import sleep -from typing import List +from typing import List, Literal from selenium.webdriver import Firefox from selenium.webdriver.common.by import By @@ -561,6 +561,32 @@ def get_manage_data_site_element(self, site: str) -> WebElement: element = self.get_element("manage-cookies-site", labels=[site]) return element + def open_autoplay_modal(self) -> BasePage: + """ + Opens the Autoplay settings modal dialog from the about:preferences#privacy page. + """ + self.open() + self.click_on("autoplay-settings-button") + self.driver.switch_to.frame(self.get_iframe()) + self.click_on("autoplay-settings") + return self + + def set_autoplay_setting_in_preferences( + self, + settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"], + ) -> BasePage: + """ + Open the Autoplay settings panel and choose a setting for all sites. + Arguments: + settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video, + "allow-audio-only" → Allow Audio but block Video + """ + self.open_autoplay_modal() + self.click_on(settings) + self.click_on("spacer") + self.click_on("autoplay-save-changes") + return self + # Utility Functions def import_bookmarks(self, browser_name: str, platform) -> BasePage: """ diff --git a/tests/audio_video/test_allow_audio_video_functionality.py b/tests/audio_video/test_allow_audio_video_functionality.py index a6b87755f..c74c5e032 100644 --- a/tests/audio_video/test_allow_audio_video_functionality.py +++ b/tests/audio_video/test_allow_audio_video_functionality.py @@ -1,6 +1,5 @@ import sys from os import environ -from time import sleep import pytest from selenium.webdriver import Firefox @@ -8,7 +7,6 @@ from modules.browser_object_tabbar import TabBar from modules.page_object_generics import GenericPage from modules.page_object_prefs import AboutPrefs -from modules.util import BrowserActions @pytest.fixture() @@ -27,40 +25,16 @@ def test_case(): @pytest.mark.noxvfb def test_allow_audio_video_functionality(driver: Firefox): """ - C330155 : 'Allow Audio and Video' functionality + C330155: 'Allow Audio and Video' functionality """ # Instantiate objects about_prefs = AboutPrefs(driver, category="privacy") - ba = BrowserActions(driver) tabs = TabBar(driver) + page = GenericPage(driver, url=TEST_URL) # Open privacy and click on the "Settings" button from Autoplay - about_prefs.open() - about_prefs.get_element("autoplay-settings-button").click() + about_prefs.set_autoplay_setting_in_preferences("allow-audio-video") - # Get the web element for the iframe - iframe = about_prefs.get_iframe() - ba.switch_to_iframe_context(iframe) - - # Click on the autoplay settings for all websites - about_prefs.get_element("autoplay-settings").click() - - # Choose allow audio and video and save changes - about_prefs.click_on("allow-audio-video") - about_prefs.get_element("spacer").click() - about_prefs.get_element("autoplay-save-changes").click() - - # Open test website and check the site is loaded and the featured video starts playing with sound - GenericPage(driver, url=TEST_URL).open() - max_retries = 3 - for attempt in range(max_retries): - try: - with driver.context(driver.CONTEXT_CHROME): - tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) - break # Success! - except AssertionError: - sleep(2) - else: - pytest.fail( - f"Tab sound status did not reach PLAYING after {max_retries} retries." - ) + # Open the website and check if the video starts playing with sound + page.open() + tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) diff --git a/tests/audio_video/test_block_audio_video_functionality.py b/tests/audio_video/test_block_audio_video_functionality.py index 13e7f87e6..012af3de7 100644 --- a/tests/audio_video/test_block_audio_video_functionality.py +++ b/tests/audio_video/test_block_audio_video_functionality.py @@ -4,7 +4,6 @@ from modules.browser_object_navigation import Navigation from modules.page_object_generics import GenericPage from modules.page_object_prefs import AboutPrefs -from modules.util import BrowserActions @pytest.fixture() @@ -21,26 +20,13 @@ def test_block_audio_video_functionality(driver: Firefox): """ # Instantiate objects about_prefs = AboutPrefs(driver, category="privacy") - ba = BrowserActions(driver) nav = Navigation(driver) + page = GenericPage(driver, url=TEST_URL) # Open privacy and click on the "Settings" button from Autoplay - about_prefs.open() - about_prefs.get_element("autoplay-settings-button").click() - - # Get the web element for the iframe - iframe = about_prefs.get_iframe() - ba.switch_to_iframe_context(iframe) - - # Click on the autoplay settings for all websites - about_prefs.get_element("autoplay-settings").click() - - # Choose block audio and video and save changes - about_prefs.click_on("block-audio-video") - about_prefs.get_element("spacer").click() - about_prefs.get_element("autoplay-save-changes").click() + about_prefs.set_autoplay_setting_in_preferences("block-audio-video") # Open test website and check the site is loaded and the featured video is not playing - GenericPage(driver, url=TEST_URL).open() - nav.click_on("autoplay-permission") - nav.element_visible("permission-popup-audio-video-blocked") + page.open() + nav.click_on("autoplay-icon-blocked") + nav.verify_autoplay_state("block") diff --git a/tests/audio_video/test_users_actions_saved_on_reload.py b/tests/audio_video/test_users_actions_saved_on_reload.py index 4b399b737..ffcb6c517 100644 --- a/tests/audio_video/test_users_actions_saved_on_reload.py +++ b/tests/audio_video/test_users_actions_saved_on_reload.py @@ -4,7 +4,6 @@ from modules.browser_object_navigation import Navigation from modules.page_object_generics import GenericPage from modules.page_object_prefs import AboutPrefs -from modules.util import BrowserActions @pytest.fixture() @@ -30,49 +29,33 @@ def test_users_actions_saved_on_reload(driver: Firefox): # Instantiate objects nav = Navigation(driver) about_prefs = AboutPrefs(driver, category="privacy") - ba = BrowserActions(driver) + page = GenericPage(driver, url=TEST_URL) - # Open Test page - GenericPage(driver, url=TEST_URL).open() + # Open the test page + page.open() - # Open the Site information panel and check "Allow Audio and Video" - nav.click_on("autoplay-permission") - nav.click_on("permission-popup-audio-blocked") - nav.click_and_hide_menu("allow-audio-video-menuitem") + # Open the Audio-Video Permission panel and check "Allow Audio and Video" + nav.set_site_autoplay_permission("allow-audio-video") - # Refresh test page and check the site information panel shows "Allow Audio and Video" + # Refresh test page and check the Audio-Video Permission panel shows "Allow Audio and Video" and the crossed off + # Play icon is no longer displayed driver.get(driver.current_url) - nav.element_visible("permission-popup-audio-video-allowed") - - # Check the Crossed off Play icon is no longer displayed - nav.element_not_visible("autoplay-icon-blocked") + nav.verify_autoplay_state("allow") # Check the website is added to the exceptions list in about:preferences#privacy - about_prefs.open() - about_prefs.get_element("autoplay-settings-button").click() - - # Get the web element for the iframe - iframe = about_prefs.get_iframe() - ba.switch_to_iframe_context(iframe) - + about_prefs.open_autoplay_modal() about_prefs.element_visible("mlb-allow-audio-video-settings") - # Open Test page - GenericPage(driver, url=TEST_URL).open() + # # Open the test page + page.open() - # Open the Site information panel and check "Block Audio and Video" - nav.click_on("autoplay-permission") - nav.click_on("permission-popup-audio-video-allowed") - nav.click_and_hide_menu("block-audio-video-menuitem") + # Open the Audio-Video Permission panel and check "Block Audio and Video" + nav.set_site_autoplay_permission("block-audio-video") - # Refresh test page and check the site information panel shows "Block Audio and Video" + # Refresh test page and check the Audio-Video Permission panel shows "Block Audio and Video" driver.get(driver.current_url) - nav.element_visible("permission-popup-audio-video-blocked") - nav.element_visible("autoplay-icon-blocked") + nav.verify_autoplay_state("block") # Revisit test page and check Site information panel shows "Block Audio and Video" - GenericPage(driver, url=TEST_URL).open() - nav.element_visible("permission-popup-audio-video-blocked") - - # Check the Crossed off Play icon is displayed - nav.element_visible("autoplay-icon-blocked") + page.open() + nav.verify_autoplay_state("block") diff --git a/tests/preferences/test_clear_cookie_data.py b/tests/preferences/test_clear_cookie_data.py index 540e1cf64..512f2beef 100644 --- a/tests/preferences/test_clear_cookie_data.py +++ b/tests/preferences/test_clear_cookie_data.py @@ -1,3 +1,6 @@ +import sys +from os import environ + import pytest from selenium.webdriver import Firefox @@ -10,6 +13,9 @@ def test_case(): return "143627" +WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win") + + def open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions): about_prefs.open() clear_data_popup = about_prefs.press_button_get_popup_dialog_iframe("Clear Data") @@ -17,6 +23,7 @@ def open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions): return about_prefs.get_clear_cookie_data_value() +@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows GA, tracked in 1990570") def test_clear_cookie_data(driver: Firefox): """ C143627: Cookies and site data can be cleared via the "Clear Data" panel diff --git a/tests/scrolling_panning_zooming/test_zoom_text_only.py b/tests/scrolling_panning_zooming/test_zoom_text_only.py index 629cdae22..96d2160bf 100644 --- a/tests/scrolling_panning_zooming/test_zoom_text_only.py +++ b/tests/scrolling_panning_zooming/test_zoom_text_only.py @@ -84,6 +84,7 @@ def reject_consent_page(web_page: GenericPage): pass +@pytest.mark.skip(reason="Tracked in bug 1991139") @pytest.mark.ci @pytest.mark.noxvfb def test_zoom_text_only_from_settings(