Skip to content

Commit 75bbbdd

Browse files
authored
Merge pull request #813 from mozilla/anca/refactoring-audio-video
Anca/ Refactor Audio-Video
2 parents c56fdd2 + 1e7ea84 commit 75bbbdd

File tree

9 files changed

+108
-93
lines changed

9 files changed

+108
-93
lines changed

modules/browser_object_navigation.py

Lines changed: 41 additions & 0 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
@@ -658,3 +659,43 @@ def expect_bookmarks_toolbar_visibility(self, expected: bool) -> None:
658659
self.expect_element_attribute_contains(
659660
self.bookmarks_toolbar, "collapsed", expected_value
660661
)
662+
663+
#
664+
def set_site_autoplay_permission(
665+
self,
666+
settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"],
667+
) -> BasePage:
668+
"""
669+
Open the Site audio-video permission panel and set a specific autoplay setting.
670+
671+
Arguments:
672+
settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video,
673+
"allow-audio-only" → Allow Audio but block Video
674+
"""
675+
self.click_on("autoplay-icon-blocked")
676+
677+
if settings == "allow-audio-video":
678+
self.element_clickable("permission-popup-audio-blocked")
679+
self.click_on("permission-popup-audio-blocked")
680+
self.click_and_hide_menu("allow-audio-video-menuitem")
681+
682+
elif settings == "block-audio-video":
683+
self.element_clickable("permission-popup-audio-video-allowed")
684+
self.click_and_hide_menu("block-audio-video-menuitem")
685+
686+
elif settings == "allow-audio-only":
687+
self.element_clickable("permission-popup-audio-video-allowed")
688+
self.click_and_hide_menu("allow-audio-only-menuitem")
689+
return self
690+
691+
def verify_autoplay_state(self, expected: Literal["allow", "block"]) -> None:
692+
"""Verify the current state of the autoplay permission panel and icon.
693+
Arguments:
694+
expected: "allow" → Allow Audio and Video, "block" → Block Audio and Video
695+
"""
696+
if expected == "allow":
697+
self.element_visible("permission-popup-audio-video-allowed")
698+
self.element_not_visible("autoplay-icon-blocked")
699+
else:
700+
self.element_visible("permission-popup-audio-video-blocked")
701+
self.element_visible("autoplay-icon-blocked")

modules/browser_object_tabbar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ def get_tab_title(self, tab_element: WebElement) -> str:
136136
tab_label = tab_element.find_element(*self.get_selector("tab-title"))
137137
return tab_label.text
138138

139+
@BasePage.context_chrome
139140
def expect_tab_sound_status(
140141
self, identifier: Union[str, int], status: MediaStatus
141142
) -> BasePage:
142-
"""Check to see if the tab has an expected MediaStatus"""
143+
"""
144+
Check to see if the tab has an expected MediaStatus
145+
"""
143146
tab = self.get_tab(identifier)
144147
self.wait.until(lambda _: tab.get_attribute(status) is not None)
145148
return self

modules/data/navigation.components.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,6 @@
501501
"groups": []
502502
},
503503

504-
"autoplay-permission": {
505-
"selectorData": "blocked-permissions-container",
506-
"strategy": "id",
507-
"groups": []
508-
},
509-
510504
"permissions-location-icon": {
511505
"selectorData": "permissions-granted-icon",
512506
"strategy": "id",

modules/page_object_prefs.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22
import re
33
from time import sleep
4-
from typing import List
4+
from typing import List, Literal
55

66
from selenium.webdriver import Firefox
77
from selenium.webdriver.common.by import By
@@ -561,6 +561,32 @@ 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_autoplay_modal(self) -> BasePage:
565+
"""
566+
Opens the Autoplay settings modal dialog from the about:preferences#privacy page.
567+
"""
568+
self.open()
569+
self.click_on("autoplay-settings-button")
570+
self.driver.switch_to.frame(self.get_iframe())
571+
self.click_on("autoplay-settings")
572+
return self
573+
574+
def set_autoplay_setting_in_preferences(
575+
self,
576+
settings: Literal["allow-audio-video", "block-audio-video", "allow-audio-only"],
577+
) -> BasePage:
578+
"""
579+
Open the Autoplay settings panel and choose a setting for all sites.
580+
Arguments:
581+
settings: "allow-audio-video" → Allow Audio and Video, "block-audio-video" → Block Audio and Video,
582+
"allow-audio-only" → Allow Audio but block Video
583+
"""
584+
self.open_autoplay_modal()
585+
self.click_on(settings)
586+
self.click_on("spacer")
587+
self.click_on("autoplay-save-changes")
588+
return self
589+
564590
# Utility Functions
565591
def import_bookmarks(self, browser_name: str, platform) -> BasePage:
566592
"""
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import sys
22
from os import environ
3-
from time import sleep
43

54
import pytest
65
from selenium.webdriver import Firefox
76

87
from modules.browser_object_tabbar import TabBar
98
from modules.page_object_generics import GenericPage
109
from modules.page_object_prefs import AboutPrefs
11-
from modules.util import BrowserActions
1210

1311

1412
@pytest.fixture()
@@ -27,40 +25,16 @@ def test_case():
2725
@pytest.mark.noxvfb
2826
def test_allow_audio_video_functionality(driver: Firefox):
2927
"""
30-
C330155 : 'Allow Audio and Video' functionality
28+
C330155: 'Allow Audio and Video' functionality
3129
"""
3230
# Instantiate objects
3331
about_prefs = AboutPrefs(driver, category="privacy")
34-
ba = BrowserActions(driver)
3532
tabs = TabBar(driver)
33+
page = GenericPage(driver, url=TEST_URL)
3634

3735
# Open privacy and click on the "Settings" button from Autoplay
38-
about_prefs.open()
39-
about_prefs.get_element("autoplay-settings-button").click()
36+
about_prefs.set_autoplay_setting_in_preferences("allow-audio-video")
4037

41-
# Get the web element for the iframe
42-
iframe = about_prefs.get_iframe()
43-
ba.switch_to_iframe_context(iframe)
44-
45-
# Click on the autoplay settings for all websites
46-
about_prefs.get_element("autoplay-settings").click()
47-
48-
# Choose allow audio and video and save changes
49-
about_prefs.click_on("allow-audio-video")
50-
about_prefs.get_element("spacer").click()
51-
about_prefs.get_element("autoplay-save-changes").click()
52-
53-
# Open test website and check the site is loaded and the featured video starts playing with sound
54-
GenericPage(driver, url=TEST_URL).open()
55-
max_retries = 3
56-
for attempt in range(max_retries):
57-
try:
58-
with driver.context(driver.CONTEXT_CHROME):
59-
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)
60-
break # Success!
61-
except AssertionError:
62-
sleep(2)
63-
else:
64-
pytest.fail(
65-
f"Tab sound status did not reach PLAYING after {max_retries} retries."
66-
)
38+
# Open the website and check if the video starts playing with sound
39+
page.open()
40+
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)

tests/audio_video/test_block_audio_video_functionality.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from modules.browser_object_navigation import Navigation
55
from modules.page_object_generics import GenericPage
66
from modules.page_object_prefs import AboutPrefs
7-
from modules.util import BrowserActions
87

98

109
@pytest.fixture()
@@ -21,26 +20,13 @@ def test_block_audio_video_functionality(driver: Firefox):
2120
"""
2221
# Instantiate objects
2322
about_prefs = AboutPrefs(driver, category="privacy")
24-
ba = BrowserActions(driver)
2523
nav = Navigation(driver)
24+
page = GenericPage(driver, url=TEST_URL)
2625

2726
# Open privacy and click on the "Settings" button from Autoplay
28-
about_prefs.open()
29-
about_prefs.get_element("autoplay-settings-button").click()
30-
31-
# Get the web element for the iframe
32-
iframe = about_prefs.get_iframe()
33-
ba.switch_to_iframe_context(iframe)
34-
35-
# Click on the autoplay settings for all websites
36-
about_prefs.get_element("autoplay-settings").click()
37-
38-
# Choose block audio and video and save changes
39-
about_prefs.click_on("block-audio-video")
40-
about_prefs.get_element("spacer").click()
41-
about_prefs.get_element("autoplay-save-changes").click()
27+
about_prefs.set_autoplay_setting_in_preferences("block-audio-video")
4228

4329
# Open test website and check the site is loaded and the featured video is not playing
44-
GenericPage(driver, url=TEST_URL).open()
45-
nav.click_on("autoplay-permission")
46-
nav.element_visible("permission-popup-audio-video-blocked")
30+
page.open()
31+
nav.click_on("autoplay-icon-blocked")
32+
nav.verify_autoplay_state("block")

tests/audio_video/test_users_actions_saved_on_reload.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from modules.browser_object_navigation import Navigation
55
from modules.page_object_generics import GenericPage
66
from modules.page_object_prefs import AboutPrefs
7-
from modules.util import BrowserActions
87

98

109
@pytest.fixture()
@@ -30,49 +29,33 @@ def test_users_actions_saved_on_reload(driver: Firefox):
3029
# Instantiate objects
3130
nav = Navigation(driver)
3231
about_prefs = AboutPrefs(driver, category="privacy")
33-
ba = BrowserActions(driver)
32+
page = GenericPage(driver, url=TEST_URL)
3433

35-
# Open Test page
36-
GenericPage(driver, url=TEST_URL).open()
34+
# Open the test page
35+
page.open()
3736

38-
# Open the Site information panel and check "Allow Audio and Video"
39-
nav.click_on("autoplay-permission")
40-
nav.click_on("permission-popup-audio-blocked")
41-
nav.click_and_hide_menu("allow-audio-video-menuitem")
37+
# Open the Audio-Video Permission panel and check "Allow Audio and Video"
38+
nav.set_site_autoplay_permission("allow-audio-video")
4239

43-
# 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
4442
driver.get(driver.current_url)
45-
nav.element_visible("permission-popup-audio-video-allowed")
46-
47-
# Check the Crossed off Play icon is no longer displayed
48-
nav.element_not_visible("autoplay-icon-blocked")
43+
nav.verify_autoplay_state("allow")
4944

5045
# Check the website is added to the exceptions list in about:preferences#privacy
51-
about_prefs.open()
52-
about_prefs.get_element("autoplay-settings-button").click()
53-
54-
# Get the web element for the iframe
55-
iframe = about_prefs.get_iframe()
56-
ba.switch_to_iframe_context(iframe)
57-
46+
about_prefs.open_autoplay_modal()
5847
about_prefs.element_visible("mlb-allow-audio-video-settings")
5948

60-
# Open Test page
61-
GenericPage(driver, url=TEST_URL).open()
49+
# # Open the test page
50+
page.open()
6251

63-
# Open the Site information panel and check "Block Audio and Video"
64-
nav.click_on("autoplay-permission")
65-
nav.click_on("permission-popup-audio-video-allowed")
66-
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")
6754

68-
# 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"
6956
driver.get(driver.current_url)
70-
nav.element_visible("permission-popup-audio-video-blocked")
71-
nav.element_visible("autoplay-icon-blocked")
57+
nav.verify_autoplay_state("block")
7258

7359
# Revisit test page and check Site information panel shows "Block Audio and Video"
74-
GenericPage(driver, url=TEST_URL).open()
75-
nav.element_visible("permission-popup-audio-video-blocked")
76-
77-
# Check the Crossed off Play icon is displayed
78-
nav.element_visible("autoplay-icon-blocked")
60+
page.open()
61+
nav.verify_autoplay_state("block")

tests/preferences/test_clear_cookie_data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
from os import environ
3+
14
import pytest
25
from selenium.webdriver import Firefox
36

@@ -10,13 +13,17 @@ def test_case():
1013
return "143627"
1114

1215

16+
WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
17+
18+
1319
def open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions):
1420
about_prefs.open()
1521
clear_data_popup = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
1622
ba.switch_to_iframe_context(clear_data_popup)
1723
return about_prefs.get_clear_cookie_data_value()
1824

1925

26+
@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows GA, tracked in 1990570")
2027
def test_clear_cookie_data(driver: Firefox):
2128
"""
2229
C143627: Cookies and site data can be cleared via the "Clear Data" panel

tests/scrolling_panning_zooming/test_zoom_text_only.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def reject_consent_page(web_page: GenericPage):
8484
pass
8585

8686

87+
@pytest.mark.skip(reason="Tracked in bug 1991139")
8788
@pytest.mark.ci
8889
@pytest.mark.noxvfb
8990
def test_zoom_text_only_from_settings(

0 commit comments

Comments
 (0)