Skip to content

Commit ef873c3

Browse files
soncuteancaHani Yacoub
andauthored
Anca/ Add fix manage cookies (#889)
* Add fix manage cookie * Fix test-search-suggesions * Separate method * Some refactoring * Test * flaky tests - reset the unstable mark --------- Co-authored-by: Hani Yacoub <[email protected]>
1 parent 4d61615 commit ef873c3

File tree

6 files changed

+57
-54
lines changed

6 files changed

+57
-54
lines changed

SELECTOR_INFO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,7 @@ Path to .json: modules/data/login_autofill.components.json
26172617
```
26182618
Selector Name: facebook-credentials
26192619
Selector Data: ".autocomplete-richlistbox .autocomplete-richlistitem[ac-value='username1']"
2620-
Description: Autocomplete dropdown is toggled for focused login fields on facebook page load
2620+
Description: Autocomplete dropdown is toggled for focused login fields on facebook page load
26212621
Location: Facebook page load
26222622
Path to .json: modules/data/login_autofill.components.json
26232623
```

modules/page_object_about_pages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ def remove_password_csv(self, downloads_dir):
195195
if delete_files_regex.match(file):
196196
os.remove(passwords_csv)
197197

198-
def verify_csv_export(self, downloads_folder: str, filename: str, timeout: int = 20):
198+
def verify_csv_export(
199+
self, downloads_folder: str, filename: str, timeout: int = 20
200+
):
199201
"""
200202
Wait until the exported CSV file is present, non-empty, and readable.
201203
"""

modules/page_object_prefs.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from modules.classes.credit_card import CreditCardBase
1717
from modules.components.dropdown import Dropdown
1818
from modules.page_base import BasePage
19-
from modules.util import Utilities
19+
from modules.util import BrowserActions, Utilities
2020

2121

2222
class AboutPrefs(BasePage):
@@ -786,6 +786,25 @@ def handle_unknown_content_dialog(self) -> BasePage:
786786
dialog.send_keys(Keys.ESCAPE)
787787
return self
788788

789+
def open_manage_cookies_data_dialog(self) -> BasePage:
790+
"""
791+
Open the 'Manage Cookies and Site Data' dialog safely.
792+
793+
Waits for the 'Manage browsing data' button to be clickable, clicks it to open
794+
the dialog, and switches the driver context to the dialog's iframe. After
795+
calling this method, subsequent element interactions will be within the
796+
dialog's iframe context.
797+
798+
Note: This method assumes the about:preferences page is already open.
799+
Call self.open() first if needed.
800+
"""
801+
self.element_clickable("prefs-button", labels=["Manage browsing data"])
802+
manage_data_popup = self.press_button_get_popup_dialog_iframe(
803+
"Manage browsing data"
804+
)
805+
BrowserActions(self.driver).switch_to_iframe_context(manage_data_popup)
806+
return self
807+
789808

790809
class AboutAddons(BasePage):
791810
"""

tests/password_manager/test_password_csv_correctness.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_case():
1414
return "2241522"
1515

1616

17+
@pytest.mark.unstable(reason="Bug 1996004")
1718
@pytest.mark.headed
1819
@pytest.mark.noxvfb
1920
def test_password_csv_correctness(

tests/password_manager/test_password_csv_export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_case():
1313
return "2241521"
1414

1515

16+
@pytest.mark.unstable(reason="Bug 1996005")
1617
@pytest.mark.headed
1718
@pytest.mark.noxvfb
1819
def test_password_csv_export(
Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import logging
12
from time import sleep
23

34
import pytest
4-
from pynput.keyboard import Controller, Key
55
from selenium.webdriver import Firefox
66

7-
from modules.page_object import AboutPrefs
7+
from modules.page_object_prefs import AboutPrefs
88
from modules.util import BrowserActions
99

1010

@@ -14,80 +14,60 @@ def test_case():
1414

1515

1616
COOKIE_SITE = "google.com"
17+
TEST_SITES = [
18+
"https://www.google.com",
19+
"https://www.jetbrains.com",
20+
"https://www.wikipedia.com",
21+
]
1722

1823

19-
@pytest.mark.headed
2024
@pytest.mark.noxvfb
2125
def test_manage_cookie_data(driver: Firefox):
2226
"""
23-
C143633 - Cookies and Site Data can be managed
24-
via the "Managed Cookies and Site Data" pane
27+
C143633 - Cookies and Site Data can be managed via the "Managed Cookies and Site Data" panel.
2528
"""
26-
# Instantiate objects
29+
# Initialize objects
2730
about_prefs = AboutPrefs(driver, category="privacy")
2831
ba = BrowserActions(driver)
29-
keyboard = Controller()
3032

31-
def open_manage_cookies_data_dialog():
32-
about_prefs.open()
33-
manage_data_popup = about_prefs.press_button_get_popup_dialog_iframe(
34-
"Manage browsing data"
35-
)
36-
ba.switch_to_iframe_context(manage_data_popup)
33+
# Visit some sites to add cookies
34+
for site in TEST_SITES:
35+
driver.get(site)
3736

38-
# Visit some sites to get a few cookies added to saved data
39-
driver.get("https://www.google.com")
40-
sleep(1)
41-
driver.get("https://www.jetbrains.com")
42-
sleep(1)
43-
driver.get("https://www.wikipedia.com")
44-
sleep(1)
37+
# Open the Manage Cookies dialog
38+
about_prefs.open()
39+
about_prefs.open_manage_cookies_data_dialog()
4540

46-
# Navigate to the manage data dialog of about:preferences#privacy
47-
open_manage_cookies_data_dialog()
48-
49-
# Click on one of the items from the list.
41+
# Select and remove one cookie
5042
cookie_item = about_prefs.get_manage_data_site_element(COOKIE_SITE)
5143
cookie_item.click()
44+
assert cookie_item.get_attribute("selected") == "true"
5245

53-
# The clicked on site in the list is highlighted
54-
selected = cookie_item.get_attribute("selected")
55-
assert selected == "true"
56-
57-
# Click the "Remove Selected" button.
5846
about_prefs.get_element("remove-selected-cookie-button").click()
59-
60-
# The selected item is removed from the list.
6147
about_prefs.element_does_not_exist("manage-cookies-site", labels=[COOKIE_SITE])
6248

63-
# Click on the "Remove All" button and wait for changes to take.
49+
# Remove all cookies
6450
about_prefs.get_element("remove-all-button").click()
6551
sleep(1)
66-
67-
# All the sites are removed from the list.
68-
# NOTE: There seems to be an empty placeholder element, thus 1 item is always there.
6952
cookie_list = about_prefs.get_elements("cookies-manage-data-sitelist")
7053
assert len(cookie_list) == 1
7154

72-
# Click on "Save Changes" button and wait for changes to take.
55+
# Save changes and handle confirmation alert
7356
about_prefs.get_element("manage-data-save-changes-button").click()
7457
sleep(1)
7558

76-
# Using pynput, navigate to the "Remove" button of the acceptance dialog/alert,
77-
# then send the Enter key and wait for changes to take
78-
keyboard.press(Key.tab)
79-
keyboard.release(Key.tab)
80-
sleep(0.5)
81-
keyboard.press(Key.tab)
82-
keyboard.release(Key.tab)
83-
sleep(0.5)
84-
keyboard.press(Key.enter)
85-
keyboard.release(Key.enter)
86-
sleep(1)
59+
try:
60+
alert = about_prefs.get_alert()
61+
logging.info(f"Alert text: {alert.text}")
62+
alert.accept()
63+
logging.info("Alert accepted successfully.")
64+
except Exception as e:
65+
logging.warning(f"No alert appeared or failed to handle: {e}")
8766

88-
# Navigate back to the manage data dialog of about:preferences#privacy
89-
open_manage_cookies_data_dialog()
67+
ba.switch_to_content_context()
68+
sleep(1)
9069

91-
# All the cookies and site data are deleted.
70+
# Reopen and confirm cookies cleared
71+
about_prefs.open_manage_cookies_data_dialog()
9272
cookie_list_post_remove = about_prefs.get_elements("cookies-manage-data-sitelist")
93-
assert len(cookie_list_post_remove) == 1 # NOTE: always an empty item here
73+
assert len(cookie_list_post_remove) == 1

0 commit comments

Comments
 (0)