Skip to content

Commit b3eca97

Browse files
committed
Create test and add PoM objects and methods
1 parent 8600804 commit b3eca97

File tree

6 files changed

+93
-2
lines changed

6 files changed

+93
-2
lines changed

modules/data/about_prefs.components.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,28 @@
250250
"selectorData": "contentBlockingFingerprintingProtectionCheckbox",
251251
"strategy": "id",
252252
"groups": []
253+
},
254+
255+
"cookies-shadow-root": {
256+
"selectorData": "dialog[buttons='accept,cancel']",
257+
"strategy": "css",
258+
"groups": [
259+
"doNotCache"
260+
]
261+
},
262+
263+
"clear-data-dialog-options": {
264+
"selectorData": "hbox.checkbox-label-box",
265+
"strategy": "css",
266+
"groups": []
267+
},
268+
269+
"clear-data-accept-button": {
270+
"selectorData": "[class='button-text'][value='Clear']",
271+
"strategy": "css",
272+
"shadowParent": "cookies-shadow-root",
273+
"groups": [
274+
"doNotCache"
275+
]
253276
}
254277
}

modules/page_object_about_prefs.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from modules.classes.autofill_base import AutofillAddressBase
1111
from modules.classes.credit_card import CreditCardBase
1212
from modules.page_base import BasePage
13-
from modules.util import PomUtils
13+
from modules.util import BrowserActions, PomUtils
1414

1515

1616
class AboutPrefs(BasePage):
@@ -283,3 +283,28 @@ def get_save_addresses_popup_iframe(self) -> WebElement:
283283
self.get_element("prefs-button", labels=["Saved addresses"]).click()
284284
iframe = self.get_element("browser-popup")
285285
return iframe
286+
287+
def get_clear_cookie_data_value(self) -> int:
288+
"""
289+
With the 'Clear browsing data and cookies' popup open,
290+
returns the <memory used> value of the option for 'Cookies and site data (<memory used>)'.
291+
The <memory used> value for no cookies is '0 bytes', otherwise values are '### MB', or '### KB'
292+
"""
293+
# Find the dialog option elements containing the checkbox label
294+
options = self.get_elements("clear-data-dialog-options")
295+
296+
# Extract the text from the label the second option
297+
second_option = options[1]
298+
label_text = second_option.text
299+
print(f"The text of the option is: {label_text}")
300+
301+
# Use a regular expression to find the memory usage
302+
match = re.search(r"\d+", label_text)
303+
304+
if match:
305+
number_str = match.group() # Extract the matched number as a string
306+
number = int(number_str) # Convert the number to an integer
307+
print(f"The extracted value is: {number}")
308+
return number
309+
else:
310+
print("No number found in the string")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from selenium.webdriver import Firefox
2+
3+
from modules.page_object import AboutPrefs
4+
from modules.util import BrowserActions
5+
6+
7+
def test_clear_cookie_data(driver: Firefox):
8+
"""
9+
C143627: Cookies and site data can be cleared via the "Clear Data" panel
10+
"""
11+
# Instantiate objects
12+
about_prefs = AboutPrefs(driver, category="privacy")
13+
ba = BrowserActions(driver)
14+
15+
def open_clear_cookies_data_dialog():
16+
about_prefs.open()
17+
clear_data_popup = about_prefs.press_button_get_popup_dialog_iframe(
18+
"Clear Data…"
19+
)
20+
ba.switch_to_iframe_context(clear_data_popup)
21+
22+
# Visit a site to get a cookie added to saved data
23+
driver.get("https://www.mozilla.org")
24+
25+
# Navigate to the clear data dialog of about:preferences#privacy
26+
open_clear_cookies_data_dialog()
27+
28+
# Check for a non-zero value of the 'Cookies and site data' option
29+
cookie_value = about_prefs.get_clear_cookie_data_value()
30+
assert cookie_value is not 0
31+
32+
# Then clear the cookies and site data
33+
about_prefs.get_element("clear-data-accept-button").click()
34+
35+
# Finally, check the value of the dialog option, it should be 0
36+
open_clear_cookies_data_dialog()
37+
cookie_value2 = about_prefs.get_clear_cookie_data_value()
38+
assert cookie_value2 is 0

tests/security_and_privacy/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def set_prefs(add_prefs: dict):
1111
"""Set prefs"""
1212
prefs = []
1313
prefs.extend(add_prefs)
14-
return prefs
14+
return prefs

tests/security_and_privacy/test_blocking_cryptominers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import pytest
44
from selenium.webdriver import Firefox
5+
56
from modules.browser_object_navigation import Navigation
67
from modules.page_object_about_prefs import AboutPrefs
78

89
CRYPTOMINERS_URL = "https://senglehardt.com/test/trackingprotection/test_pages/fingerprinting_and_cryptomining.html"
910

11+
1012
@pytest.fixture()
1113
def add_prefs():
1214
return []
1315

16+
1417
def test_blocking_cryptominers(driver: Firefox):
1518
# instantiate objects
1619
nav = Navigation(driver).open()

tests/security_and_privacy/test_cryptominers_blocked_and_shown_in_info_panel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import pytest
44
from selenium.webdriver import Firefox
5+
56
from modules.browser_object_navigation import Navigation
67

78
CRYPTOMINERS_URL = "https://senglehardt.com/test/trackingprotection/test_pages/fingerprinting_and_cryptomining.html"
89

10+
911
@pytest.fixture()
1012
def add_prefs():
1113
return []

0 commit comments

Comments
 (0)