Skip to content

Commit ecb1fe0

Browse files
authored
Merge pull request #115 from mozilla/sl/notifications-set-change
Verifying Set and Change Notifications
2 parents fd7a681 + 98ac7b4 commit ecb1fe0

File tree

6 files changed

+132
-1
lines changed

6 files changed

+132
-1
lines changed

modules/data/about_prefs.components.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@
258258
"groups": []
259259
},
260260

261+
"notifications-allow-button": {
262+
"selectorData": "button[class='popup-notification-primary-button primary footer-button']",
263+
"strategy": "css",
264+
"groups": []
265+
},
266+
267+
"notifications-block-button": {
268+
"selectorData": "button[class='popup-notification-secondary-button footer-button']",
269+
"strategy": "css",
270+
"groups": []
271+
},
272+
261273
"cookies-shadow-root": {
262274
"selectorData": "dialog[buttons='accept,cancel']",
263275
"strategy": "css",
@@ -281,6 +293,30 @@
281293
]
282294
},
283295

296+
"permissions-notifications-button": {
297+
"selectorData": "notificationSettingsButton",
298+
"strategy": "id",
299+
"groups": []
300+
},
301+
302+
"permissions-notifications-popup-websites": {
303+
"selectorData": "permissionsBox",
304+
"strategy": "id",
305+
"groups": []
306+
},
307+
308+
"permissions-notifications-popup-websites-item": {
309+
"selectorData": "richlistitem[origin='{name}']",
310+
"strategy": "css",
311+
"groups": []
312+
},
313+
314+
"permissions-notifications-popup-websites-item-status": {
315+
"selectorData": "website-status",
316+
"strategy": "class",
317+
"groups": []
318+
},
319+
284320
"language-dropdown": {
285321
"selectorData": "primaryBrowserLocale",
286322
"strategy": "id",

modules/data/generic_page.components.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
"groups": []
66
},
77

8+
"authorize-notifications-button": {
9+
"selectorData": "button[onclick='notify.authorize()']",
10+
"strategy": "css",
11+
"groups": []
12+
},
13+
14+
"show-notifications-button": {
15+
"selectorData": "button[onclick='notify.show()']",
16+
"strategy": "css",
17+
"groups": []
18+
},
19+
820
"mediawiki-image": {
921
"selectorData": "mw-mmv-image",
1022
"strategy": "class",

modules/page_object_about_prefs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,9 @@ def get_clear_cookie_data_value(self) -> int:
316316
return number
317317
else:
318318
print("No number found in the string")
319+
320+
def get_iframe(self) -> WebElement:
321+
"""
322+
Gets the webelement for the iframe that commonly appears in about:preferences
323+
"""
324+
return self.get_element("browser-popup")

modules/util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from os import remove
88
from random import shuffle
99
from typing import List, Literal, Union
10+
from urllib.parse import urlparse, urlunparse
1011

1112
from faker import Faker
1213
from faker.providers import internet, misc
@@ -370,6 +371,16 @@ def assert_json_value(self, json_data, jsonpath_expr, expected_value):
370371
f"Expected {expected_value}, but got {match[0].value}",
371372
)
372373

374+
def get_domain_from_url(self, url: str) -> str:
375+
"""
376+
Given a URL, it will extract the domain of the URL.
377+
378+
For example, "https://www.example.com/path/to/page?query=123#fragment" will product "https://www.example.com"
379+
"""
380+
parsed_url = urlparse(url)
381+
domain_parsed_url = parsed_url._replace(path="")
382+
return urlunparse(domain_parsed_url)
383+
373384

374385
class BrowserActions:
375386
"""

tests/address_bar_and_search/test_tile_menu_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939

4040
# first value in a tuple is the index of the card, second is the status of sponsorship
41-
card_indices = [(3, False), (0, True)]
41+
card_indices = [(4, False), (0, True)]
4242

4343

4444
def test_default_tile_hover_states(driver: Firefox):
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import logging
2+
3+
import pytest
4+
from selenium.webdriver import Firefox
5+
6+
from modules.page_object import AboutPrefs, GenericPage
7+
from modules.util import BrowserActions, Utilities
8+
9+
NOTIFICATIONS_SITE = "https://www.bennish.net/web-notifications.html"
10+
associated_labels = [
11+
("notifications-allow-button", "Allow", "granted"),
12+
("notifications-block-button", "Block", "denied"),
13+
]
14+
15+
16+
@pytest.fixture()
17+
def add_prefs():
18+
return []
19+
20+
21+
@pytest.mark.parametrize("button_data, button_text, permission", associated_labels)
22+
def test_notifications_allow(
23+
driver: Firefox, button_data: str, button_text: str, permission: str
24+
):
25+
"""
26+
C159150: verifies that changing different settings allows for notifcations to be blocked
27+
"""
28+
# instantiate objects
29+
ba = BrowserActions(driver)
30+
util = Utilities()
31+
alert_page = GenericPage(driver, url=NOTIFICATIONS_SITE).open()
32+
about_prefs = AboutPrefs(driver, category="privacy")
33+
34+
alert_page.get_element("authorize-notifications-button").click()
35+
with driver.context(driver.CONTEXT_CHROME):
36+
about_prefs.get_element(button_data).click()
37+
38+
check_notification_script = """
39+
return Notification.permission;
40+
"""
41+
permission_status = driver.execute_script(check_notification_script)
42+
43+
logging.info(f"Notification permission status: {permission_status}")
44+
assert permission_status == permission
45+
46+
about_prefs.open()
47+
about_prefs.get_element("permissions-notifications-button").click()
48+
49+
iframe = about_prefs.get_iframe()
50+
ba.switch_to_iframe_context(iframe)
51+
52+
website_permissions = about_prefs.get_elements(
53+
"permissions-notifications-popup-websites"
54+
)
55+
assert len(website_permissions) == 1
56+
57+
website_item = about_prefs.get_element(
58+
"permissions-notifications-popup-websites-item",
59+
labels=[util.get_domain_from_url(NOTIFICATIONS_SITE)],
60+
)
61+
62+
notification_website_status = about_prefs.get_element(
63+
"permissions-notifications-popup-websites-item-status",
64+
parent_element=website_item,
65+
)
66+
assert notification_website_status.get_attribute("label") == button_text

0 commit comments

Comments
 (0)