Skip to content

Commit 428a09d

Browse files
authored
Merge pull request #112 from mozilla/tw/clear-cookies
Create test and add PoM objects and methods for clear cookie data test
2 parents 582b6e5 + d790b88 commit 428a09d

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

modules/data/about_prefs.components.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,29 @@
252252
"groups": []
253253
},
254254

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+
]
276+
},
277+
255278
"language-dropdown": {
256279
"selectorData": "primaryBrowserLocale",
257280
"strategy": "id",

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):
@@ -288,3 +288,28 @@ def get_save_addresses_popup_iframe(self) -> WebElement:
288288
self.get_element("prefs-button", labels=["Saved addresses"]).click()
289289
iframe = self.get_element("browser-popup")
290290
return iframe
291+
292+
def get_clear_cookie_data_value(self) -> int:
293+
"""
294+
With the 'Clear browsing data and cookies' popup open,
295+
returns the <memory used> value of the option for 'Cookies and site data (<memory used>)'.
296+
The <memory used> value for no cookies is '0 bytes', otherwise values are '### MB', or '### KB'
297+
"""
298+
# Find the dialog option elements containing the checkbox label
299+
options = self.get_elements("clear-data-dialog-options")
300+
301+
# Extract the text from the label the second option
302+
second_option = options[1]
303+
label_text = second_option.text
304+
print(f"The text of the option is: {label_text}")
305+
306+
# Use a regular expression to find the memory usage
307+
match = re.search(r"\d+", label_text)
308+
309+
if match:
310+
number_str = match.group() # Extract the matched number as a string
311+
number = int(number_str) # Convert the number to an integer
312+
print(f"The extracted value is: {number}")
313+
return number
314+
else:
315+
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

0 commit comments

Comments
 (0)