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