Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 8 additions & 9 deletions modules/browser_object_print_preview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from time import sleep

from selenium.common import NoAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from modules.browser_object_panel_ui import PanelUi
Expand Down Expand Up @@ -54,16 +55,14 @@ def switch_to_preview_window(self) -> BasePage:
)
return self

def start_print(self, secondary_confirm=True) -> BasePage:
"""Press Enter in Print"""
@BasePage.context_content
def start_print(self) -> BasePage:
"""Press Enter in Print Preview Page."""
from pynput.keyboard import Controller, Key

self.switch_to_preview_window()
with self.driver.context(self.driver.CONTEXT_CHROME):
self.actions.send_keys_to_element(
self.get_element("print-settings-browser"), Keys.TAB + Keys.ENTER
).perform()
sleep(2)
keyboard = Controller()
keyboard.tap(Key.enter)
self.get_element("print-button").click()
sleep(2)
keyboard = Controller()
keyboard.tap(Key.enter)
return self
37 changes: 30 additions & 7 deletions modules/components/dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ class Dropdown(Region):
def __init__(self, page, require_shadow=True, **kwargs):
super().__init__(page, **kwargs)
self.utils = PomUtils(self.page.driver)
self.is_search_dropdown = (
page.__class__.__name__ == "AboutPrefs"
and page.url_kwargs.get("category") == "search"
)
if require_shadow:
self.shadow_elements = self.utils.get_shadow_content(self.root)
self.dropmarker = next(
el for el in self.shadow_elements if el.tag_name == "dropmarker"
el
for el in self.shadow_elements
if el.tag_name == "dropmarker"
or el.get_attribute("class") == "select-wrapper with-icon"
)

@property
Expand All @@ -38,11 +45,21 @@ def select_option(
except AttributeError:
self.root.click()

matching_menuitems = [
el
for el in self.root.find_elements(By.CSS_SELECTOR, option_tag)
if el.get_attribute(label_name) == option_name
]
if self.is_search_dropdown:
panel_element = next(
el for el in self.shadow_elements if el.tag_name == "panel-list"
)
matching_menuitems = [
el
for el in panel_element.find_elements(By.TAG_NAME, "panel-item")
if option_name in el.text
]
else:
matching_menuitems = [
el
for el in self.root.find_elements(By.CSS_SELECTOR, option_tag)
if el.get_attribute(label_name) == option_name
]
if len(matching_menuitems) == 0:
return False
elif len(matching_menuitems) == 1:
Expand All @@ -51,7 +68,13 @@ def select_option(
else:
matching_menuitems[0].click()
if wait_for_selection:
self.wait.until(EC.element_to_be_selected(matching_menuitems[0]))
if self.is_search_dropdown:
panel_trigger = self.dropmarker.find_element(
By.CLASS_NAME, "panel-trigger"
)
self.wait.until(lambda _: panel_trigger.text == option_name)
else:
self.wait.until(EC.element_to_be_selected(matching_menuitems[0]))
# self.root.send_keys(Keys.ESCAPE)
return self
else:
Expand Down
11 changes: 9 additions & 2 deletions modules/data/about_prefs.components.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"groups": []
},
"import-browser-data": {
"selectorData": "button[id='data-migration']",
"selectorData": "moz-box-button[id='data-migration']",
"strategy": "css",
"groups": []
},
Expand Down Expand Up @@ -366,7 +366,7 @@
"groups": []
},
"history-privacy-label": {
"selectorData": "historyPane",
"selectorData": "historyMode",
"strategy": "id",
"groups": []
},
Expand Down Expand Up @@ -619,5 +619,12 @@
"selectorData": "historySuggestion",
"strategy": "id",
"groups": []
},
"history-option-select": {
"selectorData": "select[id='input']",
"strategy": "css",
"shadowParent": "history_menulist",
"groups": [
]
}
}
15 changes: 15 additions & 0 deletions modules/data/print_preview.components.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@
"selectorData": "browser.printSettingsBrowser",
"strategy": "css",
"groups": []
},
"footer-button-group": {
"selectorData": "button-container",
"strategy": "id",
"groups": []
},
"print-button": {
"selectorData": "print-button",
"strategy": "id",
"groups": []
},
"cancel-button": {
"selectorData": "cancel-button",
"strategy": "id",
"groups": []
}
}
16 changes: 12 additions & 4 deletions modules/page_object_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ def select_search_suggestions_in_address_bar(self, value: bool = True) -> BasePa

def search_engine_dropdown(self) -> Dropdown:
"""Returns the Dropdown region for search engine prefs"""
self.get_element("search-engine-dropdown-root")
return Dropdown(
self, self.driver, root=self.get_element("search-engine-dropdown-root")
)
return Dropdown(self, root=self.get_element("search-engine-dropdown-root"))

def find_in_settings(self, term: str) -> BasePage:
"""Search via the Find in Settings bar, return self."""
Expand Down Expand Up @@ -241,6 +238,17 @@ def get_history_menulist(self) -> WebElement:
"""
return self.get_element("history_menulist")

def set_history_option(self, option: str):
"""
Set the history option in about:preferences.
"""
history_menulist = self.get_history_menulist()
self.driver.execute_script("arguments[0].scrollIntoView();", history_menulist)
sleep(1)
menulist_popup = Select(self.get_element("history-option-select"))
menulist_popup.select_by_value(option)
return self

# Payment and Address Management
def verify_cc_json(
self, cc_info_json: dict, credit_card_fill_obj: CreditCardBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def test_chrome_bookmarks_imported(chrome_bookmarks, driver: Firefox, sys_platfo
pytest.skip("Google Chrome not installed or directory could not be created")
about_prefs = AboutPrefs(driver, category="General")
about_prefs.open()
about_prefs.click_on("import-browser-data")
about_prefs.import_bookmarks("Chrome", sys_platform)
toolbar = Navigation(driver)
toolbar.confirm_bookmark_exists(TEST_PAGE_TITLE)
16 changes: 2 additions & 14 deletions tests/preferences/test_never_remember_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from modules.page_object import AboutPrefs

Expand All @@ -27,20 +28,7 @@ def test_never_remember_history(driver: Firefox, sys_platform: str):
about_prefs = AboutPrefs(driver, category="privacy").open()

# Change the settings to not remember the browser history
history_menulist = about_prefs.get_history_menulist()
menulist_popup = history_menulist.find_element(By.TAG_NAME, "menupopup")
options = menulist_popup.find_elements(By.TAG_NAME, "menuitem")

# Scrolling for visibility
driver.execute_script("arguments[0].scrollIntoView();", history_menulist)
time.sleep(1)
current_selection = history_menulist.get_attribute("value")

if current_selection != "dontremember":
for option in options:
if option.get_attribute("value") == "dontremember":
option.click()
break
about_prefs.set_history_option("dontremember")

# Verify that the pref is set to True
profile_path = driver.capabilities["moz:profile"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from selenium.webdriver import Firefox

from modules.browser_object import PanelUi
from modules.page_object import AboutPrefs, GoogleSearch
from modules.browser_object_navigation import Navigation
from modules.page_object import AboutPrefs
from modules.util import BrowserActions


Expand All @@ -18,17 +19,14 @@ def test_cookies_not_saved_private_browsing(driver: Firefox):
# Instantiate objs
about_prefs = AboutPrefs(driver, category="privacy")
panel_ui = PanelUi(driver)
google_search = GoogleSearch(driver)
nav = Navigation(driver)
ba = BrowserActions(driver)

# Open new private window
panel_ui.open_and_switch_to_new_window("private")

# Open the Google page and perform a search
google_search.open()
google_search.type_in_search_bar("hello")
google_search.press_enter_search_bar()
google_search.wait_for_page_to_load()
nav.search("hello")

# Close the page and switch to first tab
driver.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_never_remember_browsing_history_settings(driver: Firefox):
login_exceptions = about_prefs.get_element("logins-exceptions")
assert login_exceptions.get_attribute("disabled") == "true"

about_prefs.element_has_text("history-privacy-label", HISTORY_LABEL_TEXT)
history_mode_description = about_prefs.get_element("history-privacy-label")
assert history_mode_description.get_attribute("description") == HISTORY_LABEL_TEXT


def test_never_remember_browsing_history_from_panel(driver: Firefox):
Expand Down
Loading