Skip to content

Commit e767119

Browse files
committed
Avoid duplication
1 parent 391d453 commit e767119

File tree

5 files changed

+58
-43
lines changed

5 files changed

+58
-43
lines changed

modules/browser_object_navigation.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Literal
23

34
from selenium.common.exceptions import TimeoutException
45
from selenium.webdriver import ActionChains, Firefox
@@ -659,10 +660,40 @@ def expect_bookmarks_toolbar_visibility(self, expected: bool) -> None:
659660
self.bookmarks_toolbar, "collapsed", expected_value
660661
)
661662

662-
def open_audio_video_permission(self) -> BasePage:
663-
"""Open the Site information panel and select "Allow Audio and Video" """
663+
#
664+
def set_site_autoplay_permission(self, settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"]) -> BasePage:
665+
"""
666+
Open the Site audio-video permission panel and set a specific autoplay setting.
667+
668+
Arguments:
669+
settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video,
670+
"allow-audio-only" → Allow Audio but block Video
671+
"""
664672
self.click_on("autoplay-icon-blocked")
665-
self.element_clickable("permission-popup-audio-blocked")
666-
self.click_on("permission-popup-audio-blocked")
667-
self.click_and_hide_menu("allow-audio-video-menuitem")
673+
674+
if settings == "allow-audio-video":
675+
self.element_clickable("permission-popup-audio-blocked")
676+
self.click_on("permission-popup-audio-blocked")
677+
self.click_and_hide_menu("allow-audio-video-menuitem")
678+
679+
elif settings == "block-audio-video":
680+
self.element_clickable("permission-popup-audio-video-allowed")
681+
self.click_and_hide_menu("block-audio-video-menuitem")
682+
683+
elif settings == "allow-audio-only":
684+
self.element_clickable("permission-popup-audio-video-allowed")
685+
self.click_and_hide_menu("allow-audio-only-menuitem")
668686
return self
687+
688+
def verify_autoplay_state(self, expected: Literal["allow", "block"]) -> None:
689+
""" Verify the current state of the autoplay permission panel and icon.
690+
Arguments:
691+
expected: "allow" → Allow Audio and Video, "block" → Block Audio and Video
692+
"""
693+
if expected == "allow":
694+
self.element_visible("permission-popup-audio-video-allowed")
695+
self.element_not_visible("autoplay-icon-blocked")
696+
else:
697+
self.element_visible("permission-popup-audio-video-blocked")
698+
self.element_visible("autoplay-icon-blocked")
699+

modules/page_object_prefs.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def get_manage_data_site_element(self, site: str) -> WebElement:
561561
element = self.get_element("manage-cookies-site", labels=[site])
562562
return element
563563

564-
def open_autopaly_modal(self) -> BasePage:
564+
def open_autoplay_modal(self) -> BasePage:
565565
"""
566566
Opens the Autoplay settings modal dialog from the about:preferences#privacy page.
567567
"""
@@ -571,23 +571,15 @@ def open_autopaly_modal(self) -> BasePage:
571571
self.click_on("autoplay-settings")
572572
return self
573573

574-
def set_autoplay_setting(
575-
self,
576-
settings: Literal[
577-
"allow-audio-video",
578-
"block-audio-video",
579-
"allow-audio-only",
580-
],
581-
) -> "AboutPrefs":
574+
def set_autoplay_setting_in_preferences(
575+
self, settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"]) -> BasePage:
582576
"""
583-
Open the Autoplay settings panel and choose a policy for all sites.
577+
Open the Autoplay settings panel and choose a setting for all sites.
584578
Arguments:
585-
policy : Literal["allow-audio-video", "block-audio-video", "allow-audio-only"]
586-
- "allow-audio-video": Allow both audio and video autoplay
587-
- "block-audio-video": Block both audio and video autoplay
588-
- "allow-audio-only": Allow audio but block video autoplay
579+
settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video,
580+
"allow-audio-only" → Allow Audio but block Video
589581
"""
590-
self.open_autopaly_modal()
582+
self.open_autoplay_modal()
591583
self.click_on(settings)
592584
self.click_on("spacer")
593585
self.click_on("autoplay-save-changes")

tests/audio_video/test_allow_audio_video_functionality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_allow_audio_video_functionality(driver: Firefox):
3333
page = GenericPage(driver, url=TEST_URL)
3434

3535
# Open privacy and click on the "Settings" button from Autoplay
36-
about_prefs.set_autoplay_setting("allow-audio-video")
36+
about_prefs.set_autoplay_setting_in_preferences("allow-audio-video")
3737

3838
# Open the website and check if the video starts playing with sound
3939
page.open()

tests/audio_video/test_block_audio_video_functionality.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test_block_audio_video_functionality(driver: Firefox):
2424
page = GenericPage(driver, url=TEST_URL)
2525

2626
# Open privacy and click on the "Settings" button from Autoplay
27-
about_prefs.set_autoplay_setting("block-audio-video")
27+
about_prefs.set_autoplay_setting_in_preferences("block-audio-video")
2828

2929
# Open test website and check the site is loaded and the featured video is not playing
3030
page.open()
3131
nav.click_on("autoplay-icon-blocked")
32-
nav.element_visible("permission-popup-audio-video-blocked")
32+
nav.verify_autoplay_state("block")

tests/audio_video/test_users_actions_saved_on_reload.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,31 @@ def test_users_actions_saved_on_reload(driver: Firefox):
3131
about_prefs = AboutPrefs(driver, category="privacy")
3232
page = GenericPage(driver, url=TEST_URL)
3333

34-
# Open Test page
34+
# Open the test page
3535
page.open()
3636

3737
# Open the Audio-Video Permission panel and check "Allow Audio and Video"
38-
nav.open_audio_video_permission()
38+
nav.set_site_autoplay_permission("allow-audio-video")
3939

40-
# Refresh test page and check the site information panel shows "Allow Audio and Video"
40+
# Refresh test page and check the Audio-Video Permission panel shows "Allow Audio and Video" and the crossed off
41+
# Play icon is no longer displayed
4142
driver.get(driver.current_url)
42-
nav.element_visible("permission-popup-audio-video-allowed")
43-
44-
# Check the Crossed off Play icon is no longer displayed
45-
nav.element_not_visible("autoplay-icon-blocked")
43+
nav.verify_autoplay_state("allow")
4644

4745
# Check the website is added to the exceptions list in about:preferences#privacy
48-
about_prefs.open_autopaly_modal()
46+
about_prefs.open_autoplay_modal()
4947
about_prefs.element_visible("mlb-allow-audio-video-settings")
5048

51-
# # Open Test page
49+
# # Open the test page
5250
page.open()
5351

54-
# Open the Site information panel and check "Block Audio and Video"
55-
nav.click_on("autoplay-icon-blocked")
56-
nav.click_on("permission-popup-audio-video-allowed")
57-
nav.click_and_hide_menu("block-audio-video-menuitem")
52+
# Open the Audio-Video Permission panel and check "Block Audio and Video"
53+
nav.set_site_autoplay_permission("block-audio-video")
5854

59-
# Refresh test page and check the site information panel shows "Block Audio and Video"
55+
# Refresh test page and check the Audio-Video Permission panel shows "Block Audio and Video"
6056
driver.get(driver.current_url)
61-
nav.element_visible("permission-popup-audio-video-blocked")
62-
nav.element_visible("autoplay-icon-blocked")
57+
nav.verify_autoplay_state("block")
6358

6459
# Revisit test page and check Site information panel shows "Block Audio and Video"
6560
page.open()
66-
nav.element_visible("permission-popup-audio-video-blocked")
67-
68-
# Check the Crossed off Play icon is displayed
69-
nav.element_visible("autoplay-icon-blocked")
61+
nav.verify_autoplay_state("block")

0 commit comments

Comments
 (0)