|
| 1 | +import os |
| 2 | +import time |
| 3 | + |
| 4 | +import pytest |
| 5 | +from selenium.webdriver import Firefox |
| 6 | +from selenium.webdriver.common.by import By |
| 7 | + |
| 8 | +from modules.page_object import AboutPrefs |
| 9 | + |
| 10 | + |
| 11 | +# make sure Firefox remembers history |
| 12 | +@pytest.fixture() |
| 13 | +def add_prefs(): |
| 14 | + return [("browser.privatebrowsing.autostart", False)] |
| 15 | + |
| 16 | + |
| 17 | +def test_never_remember_history(driver: Firefox, sys_platform: str): |
| 18 | + """ |
| 19 | + C143604: Make sure to set the pref via about:preferences, then check in about:config that the pref has been changed |
| 20 | + """ |
| 21 | + |
| 22 | + about_prefs = AboutPrefs(driver, category="privacy").open() |
| 23 | + |
| 24 | + # Change the settings to not remember the browser history |
| 25 | + history_menulist = about_prefs.get_history_menulist() |
| 26 | + menulist_popup = history_menulist.find_element(By.TAG_NAME, "menupopup") |
| 27 | + options = menulist_popup.find_elements(By.TAG_NAME, "menuitem") |
| 28 | + |
| 29 | + # Scrolling for visibility |
| 30 | + driver.execute_script("arguments[0].scrollIntoView();", history_menulist) |
| 31 | + time.sleep(1) |
| 32 | + current_selection = history_menulist.get_attribute("value") |
| 33 | + |
| 34 | + if current_selection != "dontremember": |
| 35 | + for option in options: |
| 36 | + if option.get_attribute("value") == "dontremember": |
| 37 | + option.click() |
| 38 | + break |
| 39 | + |
| 40 | + # Verify that the pref is set to True |
| 41 | + profile_path = driver.capabilities["moz:profile"] |
| 42 | + prefs_file_path = os.path.join(profile_path, "prefs.js") |
| 43 | + |
| 44 | + # Read the contents of the 'prefs.js' file to check for the preference |
| 45 | + with open(prefs_file_path, "r") as prefs_file: |
| 46 | + prefs_content = prefs_file.read() |
| 47 | + |
| 48 | + # Check that the preference is now True |
| 49 | + preference_string = 'user_pref("browser.privatebrowsing.autostart", true);' |
| 50 | + assert ( |
| 51 | + preference_string in prefs_content |
| 52 | + ), f"The preference {preference_string} is not set correctly." |
0 commit comments