Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions tests/preferences/test_clear_cookie_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
from selenium.webdriver import Firefox
from selenium.webdriver.support.ui import WebDriverWait

from modules.page_object import AboutPrefs
from modules.util import BrowserActions
Expand All @@ -17,33 +18,46 @@ def test_case():


def open_clear_cookies_data_dialog(about_prefs: AboutPrefs, ba: BrowserActions):
"""
Open about:preferences#privacy, show 'Clear Data' dialog, switch into its iframe,
read 'Cookies and site data' value, then switch back to content context.
"""
about_prefs.open()
clear_data_popup = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
ba.switch_to_iframe_context(clear_data_popup)
return about_prefs.get_clear_cookie_data_value()

iframe = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
ba.switch_to_iframe_context(iframe)
value = about_prefs.get_clear_cookie_data_value()
ba.switch_to_content_context()
return value

@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows GA, tracked in 1990570")
#@pytest.mark.skipif(WIN_GHA, reason="Test unstable in Windows GA, tracked in 1990570")
def test_clear_cookie_data(driver: Firefox):
"""
C143627: Cookies and site data can be cleared via the "Clear Data" panel
C143627: Cookies and site data can be cleared via the 'Clear Data' panel
"""
# Instantiate objects
about_prefs = AboutPrefs(driver, category="privacy")
ba = BrowserActions(driver)
wait = WebDriverWait(driver, 20)

# Visit a site to get a cookie added to saved data
# 1) Visit a site so Firefox stores site data/cookies
driver.get("https://www.wikipedia.com")

# Navigate to the clear data dialog of about:preferences#privacy
# Check for a non-zero value of the 'Cookies and site data' option
cookie_value = open_clear_cookies_data_dialog(about_prefs, ba)
assert cookie_value > 0
# 2) There should be something to clear (> 0)
initial = open_clear_cookies_data_dialog(about_prefs, ba)
assert initial > 0, f"Expected cookie/site data > 0 before clearing, got {initial}"

# Then clear the cookies and site data
# 3) Clear the data: open dialog, click 'Clear', then switch back to content
about_prefs.open()
iframe = about_prefs.press_button_get_popup_dialog_iframe("Clear Data")
ba.switch_to_iframe_context(iframe)
about_prefs.get_element("clear-data-accept-button").click()
ba.switch_to_content_context()

# 4) Re-open the dialog and wait until value becomes 0
def cleared(_):
return open_clear_cookies_data_dialog(about_prefs, ba) == 0

# Finally, check the value of the dialog option, it should be 0
wait.until(cleared)

cookie_value2 = open_clear_cookies_data_dialog(about_prefs, ba)
assert cookie_value2 == 0
# 5) Final explicit check
final = open_clear_cookies_data_dialog(about_prefs, ba)
assert final == 0, f"Expected 0 after clearing, got {final}"