Skip to content

Commit 46a6c9e

Browse files
Create Test for Play/Mute/Unmute Tabs Toggle (#814)
* Add test for toggle play/mute/unmute tabs * Remove window maximization in test setup Removed window maximization before opening video links. * Update test_play_mute_unmute_tabs_via_toggle.py Disable test on GHA * Add Delay Constants --------- Co-authored-by: Tracy <[email protected]>
1 parent 89a7a4e commit 46a6c9e

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import pytest
2+
3+
from os import environ
4+
from time import sleep
5+
6+
from pynput.mouse import Button, Controller
7+
from selenium.webdriver import Firefox
8+
from selenium.webdriver.common.by import By
9+
from selenium.webdriver.common.keys import Keys
10+
from selenium.webdriver.support import expected_conditions as EC
11+
from selenium.webdriver.support.ui import WebDriverWait
12+
13+
from modules.browser_object import ContextMenu
14+
from modules.browser_object_tabbar import TabBar
15+
from modules.page_object_generics import GenericPage
16+
17+
GHA = environ.get("GITHUB_ACTIONS") == "true"
18+
19+
20+
@pytest.fixture()
21+
def test_case():
22+
return "246981"
23+
24+
25+
@pytest.fixture()
26+
def add_to_prefs_list():
27+
return [("network.cookie.cookieBehavior", "2")]
28+
29+
30+
@pytest.mark.audio
31+
@pytest.mark.headed
32+
@pytest.mark.skipif(GHA, reason="Test unstable in Github Actions")
33+
def test_play_mute_unmute_tabs_via_toggle(driver: Firefox, sys_platform: str):
34+
"""
35+
C246981 - Verify that play/mute/unmute tabs via toggle audio works
36+
"""
37+
tabs = TabBar(driver)
38+
context_menu = ContextMenu(driver)
39+
mouse = Controller()
40+
wait = WebDriverWait(driver, 10)
41+
DELAY = 2
42+
POSITION_DELAY = 0.3
43+
44+
# Open Mozilla's Youtube Page
45+
playlist_url = "https://www.youtube.com/@Mozilla/videos"
46+
playlist_page = GenericPage(driver, url=playlist_url)
47+
playlist_page.open()
48+
49+
# Locate and open 2 latest videos in new tabs
50+
video_selector = "ytd-rich-item-renderer a#video-title-link"
51+
video_links = wait.until(
52+
EC.visibility_of_all_elements_located((By.CSS_SELECTOR, video_selector))
53+
)
54+
55+
for i in range(2):
56+
playlist_page.context_click(video_links[i])
57+
context_menu.click_and_hide_menu("context-menu-open-link-in-tab")
58+
59+
# Verify correct number of tabs opened
60+
tabs.wait_for_num_tabs(3)
61+
sleep(DELAY)
62+
63+
# Select all tabs via Control/Command click while staying on first tab
64+
modifier_key = Keys.COMMAND if sys_platform == "Darwin" else Keys.CONTROL
65+
66+
with driver.context(driver.CONTEXT_CHROME):
67+
actions = tabs.actions
68+
69+
# Hold modifier and select the video tabs
70+
actions.key_down(modifier_key)
71+
for i in range(2, 4): # Select tabs 2 and 3
72+
tab_to_select = tabs.get_tab(i)
73+
actions.click(tab_to_select)
74+
actions.key_up(modifier_key).perform()
75+
76+
# Verify tabs are selected (multiselected attribute)
77+
for i in range(2, 4):
78+
tab = tabs.get_tab(i)
79+
assert tab.get_attribute("multiselected") == "true", (
80+
f"Tab {i} should be multiselected"
81+
)
82+
83+
# Helper function to click the multi-tab audio control button
84+
def click_multi_tab_audio_button():
85+
tab = tabs.get_tab(2)
86+
element_location = tab.location
87+
element_size = tab.size
88+
window_position = driver.get_window_position()
89+
90+
inner_height = driver.execute_script("return window.innerHeight;")
91+
outer_height = driver.execute_script("return window.outerHeight;")
92+
chrome_height = outer_height - inner_height
93+
94+
element_x = (
95+
window_position["x"]
96+
+ element_location["x"]
97+
+ (element_size["width"] / 2)
98+
)
99+
element_y = (
100+
window_position["y"]
101+
+ element_location["y"]
102+
+ (element_size["height"] / 2)
103+
+ chrome_height
104+
)
105+
# Offset to click on the audio control area (left side of tab)
106+
mouse.position = (element_x - 75, element_y)
107+
sleep(POSITION_DELAY) # Small delay for mouse positioning
108+
mouse.click(Button.left, 1)
109+
sleep(DELAY) # Wait for action to take effect
110+
111+
# Click Play button
112+
click_multi_tab_audio_button()
113+
114+
# Verify all selected tabs are playing
115+
for i in [2, 3]:
116+
tabs.expect_tab_sound_status(i, tabs.MEDIA_STATUS.PLAYING)
117+
tab = tabs.get_tab(i)
118+
assert tab.get_attribute("soundplaying") is not None, (
119+
f"Tab {i} should be playing audio"
120+
)
121+
122+
# Click Mute button
123+
click_multi_tab_audio_button()
124+
125+
# Verify all selected tabs are muted
126+
for i in [2, 3]:
127+
tabs.expect_tab_sound_status(i, tabs.MEDIA_STATUS.MUTED)
128+
tab = tabs.get_tab(i)
129+
assert tab.get_attribute("muted") is not None, f"Tab {i} should be muted"
130+
131+
# Click Unmute button
132+
click_multi_tab_audio_button()
133+
134+
# Verify all selected tabs are unmuted and playing again
135+
for i in [2, 3]:
136+
tabs.expect_tab_sound_status(i, tabs.MEDIA_STATUS.PLAYING)
137+
tab = tabs.get_tab(i)
138+
assert tab.get_attribute("soundplaying") is not None, (
139+
f"Tab {i} should be playing audio after unmute"
140+
)
141+
assert tab.get_attribute("muted") is None, (
142+
f"Tab {i} should not be muted after unmute"
143+
)

0 commit comments

Comments
 (0)