Skip to content

Commit 8ecec12

Browse files
Philimon/Fix_cookies_related_tests (#843)
* changes to fix clear_cookies and manage_cookies tests * rerun tests * lint fix * fix for never remember history test * fix never remember * remove wait parameter * remove wait * workaround to open site settings * add clickable check * hack added to fix linux run * log frame data * another hack to close the dialog * add close dialog button * add expect for win run --------- Co-authored-by: Ben Chatterton <[email protected]>
1 parent ca36cc7 commit 8ecec12

File tree

7 files changed

+65
-48
lines changed

7 files changed

+65
-48
lines changed

SELECTOR_INFO.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,22 @@ Path to .json: modules/data/about_prefs.components.json
509509
```
510510
```
511511
Selector Name: prefs-button
512+
Selector Data: "moz-box-button[label^='{name}']"
513+
Description: Checkbox for a option by label of moz box button
514+
Location: about:preferences#privacy
515+
Path to .json: modules/data/about_prefs.components.json
516+
```
517+
```
518+
Selector Name: action-button
512519
Selector Data: "button[label^='{name}']"
513-
Description: Checkbox for a option by label
520+
Description: Checkbox for a option by label of normal button
521+
Location: about:preferences#privacy
522+
Path to .json: modules/data/about_prefs.components.json
523+
```
524+
```
525+
Selector Name: close-dialog
526+
Selector Data: "button[data-l10n-id='close-button']"
527+
Description: Close dialog button
514528
Location: about:preferences#privacy
515529
Path to .json: modules/data/about_prefs.components.json
516530
```

l10n_CM/Unified/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def prefs_list(add_to_prefs_list: List[tuple[str, str | bool]], region: str):
6464
("extensions.formautofill.addresses.supportedCountries", region),
6565
("browser.aboutConfig.showWarning", False),
6666
("browser.search.region", region),
67+
("extensions.formautofill.addresses.enabled", True),
68+
("extensions.formautofill.creditCards.enabled", True),
6769
]
6870
prefs.extend(add_to_prefs_list)
6971
return prefs

modules/data/about_prefs.components.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,25 @@
5555
"groups": []
5656
},
5757
"prefs-button": {
58+
"selectorData": "moz-box-button[label^='{name}']",
59+
"strategy": "css",
60+
"groups": []
61+
},
62+
"action-button": {
5863
"selectorData": "button[label^='{name}']",
5964
"strategy": "css",
6065
"groups": []
6166
},
67+
"close-dialog": {
68+
"selectorData": "button[data-l10n-id='close-button']",
69+
"strategy": "css",
70+
"groups": []
71+
},
72+
"clear-site-data-button": {
73+
"selectorData": "clearSiteDataButton",
74+
"strategy": "id",
75+
"groups": []
76+
},
6277
"saved-payments-button": {
6378
"selectorData": "[data-l10n-id='autofill-payment-methods-manage-payments-button']",
6479
"strategy": "css",
@@ -317,10 +332,15 @@
317332
"groups": []
318333
},
319334
"cookies-privacy-label": {
320-
"selectorData": "[data-l10n-id='sitedata-delete-on-close-private-browsing3']",
335+
"selectorData": "moz-message-bar[data-l10n-id='sitedata-delete-on-close-private-browsing3']",
321336
"strategy": "css",
322337
"groups": []
323338
},
339+
"history-privacy-label": {
340+
"selectorData": "historyPane",
341+
"strategy": "id",
342+
"groups": []
343+
},
324344
"cookies-delete-on-close": {
325345
"selectorData": "deleteOnClose",
326346
"strategy": "id",
@@ -336,11 +356,6 @@
336356
"strategy": "id",
337357
"groups": []
338358
},
339-
"history-privacy-label": {
340-
"selectorData": "description[data-l10n-id='history-dontremember-description']",
341-
"strategy": "css",
342-
"groups": []
343-
},
344359
"language-dropdown": {
345360
"selectorData": "primaryBrowserLocale",
346361
"strategy": "id",

modules/page_object_prefs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,22 @@ def press_button_get_popup_dialog_iframe(self, button_label: str) -> WebElement:
429429
"""
430430
Returns the iframe object for the dialog panel in the popup after pressing some button that triggers a popup
431431
"""
432+
# hack to know if the current iframe is the default browser one or not
433+
if self.get_iframe().location['x'] > 0:
434+
self.click_on('close-dialog')
432435
self.click_on("prefs-button", labels=[button_label])
433436
iframe = self.get_element("browser-popup")
434437
return iframe
435438

439+
def clear_cookies_and_get_dialog_iframe(self):
440+
"""
441+
Returns the iframe object for the dialog panel in the popup after pressing the clear site data button.
442+
"""
443+
self.element_clickable("clear-site-data-button")
444+
self.click_on("clear-site-data-button")
445+
iframe = self.get_element("browser-popup")
446+
return iframe
447+
436448
def get_saved_addresses_popup_iframe(self) -> WebElement:
437449
"""
438450
Returns the iframe object for the dialog panel in the popup
@@ -534,6 +546,8 @@ def get_clear_cookie_data_value(self) -> int | None:
534546
options = self.get_elements("clear-data-dialog-options")
535547

536548
# Extract the text from the label the second option
549+
print(f"All options: {options}")
550+
self.expect(lambda _: len(options) > 1)
537551
second_option = options[1]
538552
label_text = second_option.text
539553
print(f"The text of the option is: {label_text}")
Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from platform import system
2-
31
import pytest
42
from selenium.webdriver import Firefox
53
from selenium.webdriver.support.ui import WebDriverWait
@@ -16,49 +14,29 @@ def test_case():
1614
WEBSITE_ADDRESS = "https://www.wikipedia.com"
1715
# WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win")
1816

19-
20-
def _dialog_options_present(about_prefs: AboutPrefs) -> bool:
21-
"""Return True when the Clear Data dialog options container exists."""
22-
try:
23-
about_prefs.get_element("clear-data-dialog-options")
24-
return True
25-
except Exception:
26-
return False
27-
28-
2917
def _open_clear_cookies_data_dialog(
30-
about_prefs: AboutPrefs, ba: BrowserActions, wait: WebDriverWait
18+
about_prefs: AboutPrefs, ba: BrowserActions
3119
):
3220
"""
33-
Open about:preferences#privacy, show 'Clear Data' dialog, switch into its iframe,
34-
wait for its options container to be present, read the value, then switch back.
21+
Open about:preferences#privacy, show the 'Clear Data' dialog, switch into its iframe,
22+
wait for its option container to be present, read the value, then switch back.
3523
"""
3624
about_prefs.open()
3725

3826
# Click the button and grab the dialog iframe element
39-
dlg_iframe = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
40-
41-
# Wait until the iframe is attached and visible before switching
42-
wait.until(lambda _: dlg_iframe and dlg_iframe.is_displayed())
27+
dlg_iframe = about_prefs.clear_cookies_and_get_dialog_iframe()
4328

4429
# Enter dialog iframe
4530
ba.switch_to_iframe_context(dlg_iframe)
4631

47-
# Wait for dialog content to be ready (no custom timeout kwarg)
48-
wait.until(lambda _: _dialog_options_present(about_prefs))
49-
5032
value = about_prefs.get_clear_cookie_data_value()
5133

52-
# Always return to content context
34+
# Always return to the content context
5335
ba.switch_to_content_context()
36+
about_prefs.close_dialog_box()
5437
return value
5538

5639

57-
# @pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows GA, tracked in 1990570")
58-
@pytest.mark.skipif(
59-
system().lower().startswith("darwin") or system().lower().startswith("linux"),
60-
reason="bug 1994055",
61-
)
6240
def test_clear_cookie_data(driver: Firefox):
6341
"""
6442
C143627: Cookies and site data can be cleared via the "Clear Data" panel
@@ -71,19 +49,19 @@ def test_clear_cookie_data(driver: Firefox):
7149
driver.get(WEBSITE_ADDRESS)
7250

7351
# Open dialog and read current value (must be > 0)
74-
cookie_value = _open_clear_cookies_data_dialog(about_prefs, ba, wait)
52+
cookie_value = _open_clear_cookies_data_dialog(about_prefs, ba)
7553
assert cookie_value > 0, f"Expected cookie/site data > 0, got {cookie_value}"
7654

77-
# Clear cookies and site data: open dialog again, wait for iframe, click clear
55+
# Clear cookies and site data: open the dialog again, wait for iframe, click clear
7856
about_prefs.open()
79-
dlg_iframe = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
57+
dlg_iframe = about_prefs.clear_cookies_and_get_dialog_iframe()
8058
wait.until(lambda _: dlg_iframe and dlg_iframe.is_displayed())
8159
ba.switch_to_iframe_context(dlg_iframe)
8260
about_prefs.get_element("clear-data-accept-button").click()
8361
ba.switch_to_content_context()
8462

8563
# Wait until the dialog reports 0 (reopen/poll via helper)
86-
wait.until(lambda _: _open_clear_cookies_data_dialog(about_prefs, ba, wait) == 0)
64+
wait.until(lambda _: _open_clear_cookies_data_dialog(about_prefs, ba) == 0)
8765

88-
final_value = _open_clear_cookies_data_dialog(about_prefs, ba, wait)
66+
final_value = _open_clear_cookies_data_dialog(about_prefs, ba)
8967
assert final_value == 0, f"Expected 0 after clearing, got {final_value}"

tests/preferences/test_manage_cookie_data.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from platform import system
21
from time import sleep
32

43
import pytest
@@ -17,10 +16,6 @@ def test_case():
1716
COOKIE_SITE = "google.com"
1817

1918

20-
@pytest.mark.skipif(
21-
system().lower().startswith("darwin") or system().lower().startswith("linux"),
22-
reason="bug 1994056",
23-
)
2419
@pytest.mark.headed
2520
@pytest.mark.noxvfb
2621
def test_manage_cookie_data(driver: Firefox):
@@ -36,7 +31,7 @@ def test_manage_cookie_data(driver: Firefox):
3631
def open_manage_cookies_data_dialog():
3732
about_prefs.open()
3833
manage_data_popup = about_prefs.press_button_get_popup_dialog_iframe(
39-
"Manage Data…"
34+
"Manage browsing data"
4035
)
4136
ba.switch_to_iframe_context(manage_data_popup)
4237

tests/security_and_privacy/test_never_remember_browsing_history.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def test_never_remember_browsing_history_settings(driver: Firefox):
4949
login_exceptions = about_prefs.get_element("logins-exceptions")
5050
assert login_exceptions.get_attribute("disabled") == "true"
5151

52-
history_label = about_prefs.get_element("history-privacy-label")
53-
assert history_label.get_attribute("innerHTML") == HISTORY_LABEL_TEXT
52+
about_prefs.element_has_text("history-privacy-label", HISTORY_LABEL_TEXT)
5453

5554

5655
def test_never_remember_browsing_history_from_panel(driver: Firefox):

0 commit comments

Comments
 (0)