Skip to content

Commit cf69662

Browse files
committed
Add refactored tests 330155 and 330156
1 parent 6198202 commit cf69662

File tree

6 files changed

+45
-61
lines changed

6 files changed

+45
-61
lines changed

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: 28 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,33 @@ 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 set_autoplay_setting(
565+
self,
566+
settings: Literal[
567+
"allow-audio-video",
568+
"block-audio-video",
569+
"allow-audio-only",
570+
],
571+
) -> "AboutPrefs":
572+
"""
573+
Open the Autoplay settings panel and choose a policy for all sites.
574+
Arguments:
575+
policy : Literal["allow-audio-video", "block-audio-video", "allow-audio-only"]
576+
- "allow-audio-video": Allow both audio and video autoplay
577+
- "block-audio-video": Block both audio and video autoplay
578+
- "allow-audio-only": Allow audio but block video autoplay
579+
"""
580+
self.open()
581+
self.click_on("autoplay-settings-button")
582+
583+
self.driver.switch_to.frame(self.get_iframe())
584+
585+
self.click_on("autoplay-settings")
586+
self.click_on(settings)
587+
self.click_on("spacer")
588+
self.click_on("autoplay-save-changes")
589+
return self
590+
564591
# Utility Functions
565592
def import_bookmarks(self, browser_name: str, platform) -> BasePage:
566593
"""
Lines changed: 7 additions & 33 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()
@@ -22,45 +20,21 @@ def test_case():
2220
TEST_URL = "https://www.mlb.com/video/rockies-black-agree-on-extension"
2321

2422

25-
@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows Github Actions")
23+
# @pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows Github Actions")
2624
@pytest.mark.audio
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("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: 4 additions & 18 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("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")
30+
page.open()
31+
nav.click_on("autoplay-icon-blocked")
4632
nav.element_visible("permission-popup-audio-video-blocked")

tests/audio_video/test_users_actions_saved_on_reload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_users_actions_saved_on_reload(driver: Firefox):
3636
GenericPage(driver, url=TEST_URL).open()
3737

3838
# Open the Site information panel and check "Allow Audio and Video"
39-
nav.click_on("autoplay-permission")
39+
nav.click_on("autoplay-icon-blocked")
4040
nav.click_on("permission-popup-audio-blocked")
4141
nav.click_and_hide_menu("allow-audio-video-menuitem")
4242

@@ -61,7 +61,7 @@ def test_users_actions_saved_on_reload(driver: Firefox):
6161
GenericPage(driver, url=TEST_URL).open()
6262

6363
# Open the Site information panel and check "Block Audio and Video"
64-
nav.click_on("autoplay-permission")
64+
nav.click_on("autoplay-icon-blocked")
6565
nav.click_on("permission-popup-audio-video-allowed")
6666
nav.click_and_hide_menu("block-audio-video-menuitem")
6767

0 commit comments

Comments
 (0)