diff --git a/modules/browser_object_forget_panel.py b/modules/browser_object_forget_panel.py index ba3725672..86ec27130 100644 --- a/modules/browser_object_forget_panel.py +++ b/modules/browser_object_forget_panel.py @@ -5,16 +5,33 @@ class ForgetPanel(BasePage): """ - BOM for the forget panel + BOM for the Forget Panel """ URL_TEMPLATE = "" + def select_timeframe( + self, + timeframe: Literal["forget-five-minutes", "forget-two-hours", "forget-one-day"], + ) -> "ForgetPanel": + """ + Select a specific timeframe option in the forget panel. + This will click the option regardless of what's currently selected. + + Argument: + timeframe: Timeframe to forget. Restricted options to "forget-five-minutes", + "forget-two-hours", or "forget-one-day" + """ + self.click_on(timeframe) + return self + def forget_history( self, timeframe: Literal["forget-five-minutes", "forget-two-hours", "forget-one-day"], - ) -> BasePage: - with self.driver.context(self.driver.CONTEXT_CHROME): - self.get_element(timeframe).click() - self.get_element("forget-confirm-button").click() - return self + ) -> "ForgetPanel": + """ + Forget browsing history for a given timeframe. + """ + self.select_timeframe(timeframe) + self.click_on("forget-confirm-button") + return self diff --git a/modules/browser_object_navigation.py b/modules/browser_object_navigation.py index 5f7331d19..ad0c64467 100644 --- a/modules/browser_object_navigation.py +++ b/modules/browser_object_navigation.py @@ -342,6 +342,12 @@ def select_element_in_nav(self, element: str) -> BasePage: self.get_element(element).click() return self + @BasePage.context_chrome + def open_forget_panel(self) -> BasePage: + """Open the Forget Panel by clicking the Forget button in the toolbar.""" + self.get_element("forget-button").click() + return self + @BasePage.context_chrome def get_legacy_search_engine_label(self) -> str: """Return the displayed engine name from the legacy search bar.""" diff --git a/modules/browser_object_tabbar.py b/modules/browser_object_tabbar.py index c8ad3fa0e..8668c033e 100644 --- a/modules/browser_object_tabbar.py +++ b/modules/browser_object_tabbar.py @@ -283,12 +283,33 @@ def close_tab(self, tab: WebElement) -> BasePage: self.get_element("tab-x-icon", parent_element=tab).click() return self - def open_web_page_in_new_tab(self, web_page: BasePage, num_tabs: int) -> BasePage: + def open_single_page_in_new_tab(self, page: BasePage, num_tabs: int) -> BasePage: """ Opens a new tab, switches the driver context to the new tab, and opens the given webpage + Arguments: + page: The page object to open in the new tab + num_tabs: Expected total number of tabs after opening the new tab (used for waiting) """ self.new_tab_by_button() self.wait_for_num_tabs(num_tabs) self.driver.switch_to.window(self.driver.window_handles[-1]) - web_page.open() + page.open() + return self + + def open_multiple_tabs_with_pages(self, pages: list) -> "TabBar": + """ + Opens multiple new tabs and navigates to different pages in each tab. + + Argument: + pages: List of page objects or URLs to open in separate tabs + """ + for page in pages: + self.new_tab_by_button() + self.wait_for_num_tabs(len(self.driver.window_handles)) + self.driver.switch_to.window(self.driver.window_handles[-1]) + + if isinstance(page, str): + self.driver.get(page) + else: + page.open() return self diff --git a/tests/bookmarks_and_history/test_deleted_page_not_remembered.py b/tests/bookmarks_and_history/test_deleted_page_not_remembered.py index 021941115..ea3898ec3 100644 --- a/tests/bookmarks_and_history/test_deleted_page_not_remembered.py +++ b/tests/bookmarks_and_history/test_deleted_page_not_remembered.py @@ -19,16 +19,16 @@ def test_deleted_page_not_remembered(driver: Firefox, sys_platform): """ C216273: Verify that the deleted page from the Hamburger History submenu is not remembered or autofilled in the URL bar """ - panel_ui = PanelUi(driver) - panel_ui.open() + # Instantiate objects + panel = PanelUi(driver) nav = Navigation(driver) context_menu = ContextMenu(driver) - panel_ui.open_history_menu() - panel_ui.context_click("bookmark-by-title", labels=["Firefox Privacy Notice"]) - + # Open history menu and right-click on a specific history entry and delete it + panel.open_history_menu() + panel.context_click("bookmark-by-title", labels=["Firefox Privacy Notice"]) context_menu.click_and_hide_menu("context-menu-delete-page") - nav.type_in_awesome_bar("Firefox Privacy Notice") - with driver.context(driver.CONTEXT_CHROME): - nav.expect(lambda _: len(nav.get_elements("results-dropdown")) == 1) + # Type the deleted page name in the URL bar and verify the deleted page is not suggested + nav.type_in_awesome_bar("Firefox Privacy Notice") + nav.expect(lambda _: len(nav.get_elements("results-dropdown")) == 1) diff --git a/tests/bookmarks_and_history/test_history_menu_from_different_places.py b/tests/bookmarks_and_history/test_history_menu_from_different_places.py index 4caaf8853..e5c784b92 100644 --- a/tests/bookmarks_and_history/test_history_menu_from_different_places.py +++ b/tests/bookmarks_and_history/test_history_menu_from_different_places.py @@ -7,6 +7,7 @@ from modules.browser_object_navigation import Navigation from modules.browser_object_panel_ui import PanelUi from modules.browser_object_tabbar import TabBar +from modules.page_base import BasePage from modules.page_object_customize_firefox import CustomizeFirefox @@ -15,11 +16,15 @@ def test_case(): return "118799" +# Single-use helper kept in test file (YAGNI). Avoids duplication and/or overengineering +@BasePage.context_chrome def assert_elements_visibility(ui_object, elements: dict, source: str): - """Helper function to assert visibility of elements in a given UI source.""" + """ + Helper function to assert visibility of elements in a given UI source. + """ for name, locator in elements.items(): element = ui_object.get_element(locator) - assert element.is_displayed(), f"{name} should be visible in {source}" + assert element.is_displayed() def test_history_menu_in_different_places(driver: Firefox): @@ -28,77 +33,74 @@ def test_history_menu_in_different_places(driver: Firefox): Toolbar) """ - # 1. History options from Hamburger Menu - panel_ui = PanelUi(driver) - panel_ui.open_history_menu() - - with driver.context(driver.CONTEXT_CHROME): - hamburger_menu_elements = { - "Back Button": "history-back-button", - "History Title": "history_title", - "Recently Closed Tabs": "panel-ui-history-recently-closed", - "Recently Closed Windows": "recently_closed_windows", - "Search History": "search_history", - "Clear Recent History": "clear-recent-history", - "Recent History": "recent_history", - "Manage History": "manage_history", - } - assert_elements_visibility(panel_ui, hamburger_menu_elements, "Hamburger Menu") - - # 2. History options from Menu Bar + # 1. Verify History options from Hamburger Menu + panel = PanelUi(driver) + panel.open_history_menu() + + hamburger_menu_elements = { + "Back Button": "history-back-button", + "History Title": "history_title", + "Recently Closed Tabs": "panel-ui-history-recently-closed", + "Recently Closed Windows": "recently_closed_windows", + "Search History": "search_history", + "Clear Recent History": "clear-recent-history", + "Recent History": "recent_history", + "Manage History": "manage_history", + } + assert_elements_visibility(panel, hamburger_menu_elements, "Hamburger Menu") + + # 2. Verify History options from Menu Bar menu_bar = MenuBar(driver) if platform.system() != "Darwin": menu_bar.open_menu("History") - with driver.context(driver.CONTEXT_CHROME): - menu_bar_elements = { - "Show All History": "menu-bar-show-all-history", - "Clear Recent History": "menu-bar-clear-recent-history", - "Restore Previous Session": "menu-bar-restore-previous-session", - "Search History": "menu-bar-search-history", - "Recently Closed Tabs": "menu-bar-recently-closed-tabs", - "Recently Closed Windows": "menu-bar-recently-closed-windows", - } - assert_elements_visibility(menu_bar, menu_bar_elements, "Menu Bar") + menu_bar_elements = { + "Show All History": "menu-bar-show-all-history", + "Clear Recent History": "menu-bar-clear-recent-history", + "Restore Previous Session": "menu-bar-restore-previous-session", + "Search History": "menu-bar-search-history", + "Recently Closed Tabs": "menu-bar-recently-closed-tabs", + "Recently Closed Windows": "menu-bar-recently-closed-windows", + } + assert_elements_visibility(menu_bar, menu_bar_elements, "Menu Bar") else: print("Skipping Menu Bar verification on macOS") - # 3. History options from Toolbar (History and Library) + # 3. Verify History options from Toolbar (History and Library) customize_firefox = CustomizeFirefox(driver) tabs = TabBar(driver) nav = Navigation(driver) - panel_ui.navigate_to_customize_toolbar() + panel.navigate_to_customize_toolbar() customize_firefox.add_widget_to_toolbar("history") tabs.new_tab_by_button() tabs.switch_to_new_tab() - with driver.context(driver.CONTEXT_CHROME): - nav.click_on("history-button") + nav.click_on("history-button") - history_toolbar_elements = { - "Recently Closed Tabs": "toolbar-history-recently-closed-tabs", - "Recently Closed Windows": "toolbar-history-recently-closed-windows", - "Search History": "toolbar-history-search-history", - "Clear Recent History": "toolbar-history-clear-recent-history", - "Recent History": "toolbar-history-recent_history", - "Manage History": "toolbar-history-manage_history", - } - assert_elements_visibility(nav, history_toolbar_elements, "Toolbar History") + history_toolbar_elements = { + "Recently Closed Tabs": "toolbar-history-recently-closed-tabs", + "Recently Closed Windows": "toolbar-history-recently-closed-windows", + "Search History": "toolbar-history-search-history", + "Clear Recent History": "toolbar-history-clear-recent-history", + "Recent History": "toolbar-history-recent_history", + "Manage History": "toolbar-history-manage_history", + } + assert_elements_visibility(nav, history_toolbar_elements, "Toolbar History") - panel_ui.open_panel_menu() - panel_ui.navigate_to_customize_toolbar() - customize_firefox.add_widget_to_toolbar("library") + panel.open_panel_menu() + panel.navigate_to_customize_toolbar() + customize_firefox.add_widget_to_toolbar("library") - tabs.new_tab_by_button() - tabs.switch_to_new_tab() + tabs.new_tab_by_button() + tabs.switch_to_new_tab() - nav.click_on("library-button") - nav.click_on("library-history-submenu-button") + nav.click_on("library-button") + nav.click_on("library-history-submenu-button") - library_toolbar_elements = ( - history_toolbar_elements # Reuse the same locators from a different path - ) - assert_elements_visibility(nav, library_toolbar_elements, "Toolbar Library") + library_toolbar_elements = ( + history_toolbar_elements # Reuse the same locators from a different path + ) + assert_elements_visibility(nav, library_toolbar_elements, "Toolbar Library") diff --git a/tests/bookmarks_and_history/test_import_bookmarks_edge.py b/tests/bookmarks_and_history/test_import_bookmarks_edge.py index 4f11dbed9..779d52896 100644 --- a/tests/bookmarks_and_history/test_import_bookmarks_edge.py +++ b/tests/bookmarks_and_history/test_import_bookmarks_edge.py @@ -5,7 +5,7 @@ import pytest from selenium.webdriver import Firefox -from modules.browser_object_navigation import Navigation +from modules.browser_object import Navigation from modules.page_object import AboutPrefs NEWS_ARTICLE_TITLE = "Level 1, 2 evacuations issued for fire burning in Chelan" diff --git a/tests/bookmarks_and_history/test_opened_website_in_new_tab_present_in_hamburger_history_menu.py b/tests/bookmarks_and_history/test_opened_website_in_new_tab_present_in_hamburger_history_menu.py index abe3fe8ba..162bf5f2c 100644 --- a/tests/bookmarks_and_history/test_opened_website_in_new_tab_present_in_hamburger_history_menu.py +++ b/tests/bookmarks_and_history/test_opened_website_in_new_tab_present_in_hamburger_history_menu.py @@ -29,7 +29,7 @@ def test_the_website_opened_in_new_tab_is_present_in_history_menu(driver: Firefo panel = PanelUi(driver) # Open a desired webpage in a new tab - tabs.open_web_page_in_new_tab(page, 2) + tabs.open_single_page_in_new_tab(page, 2) page.url_contains("wikipedia") # Verify the opened webpage from last step is present in the Hamburger Menu, History section and is on top of the diff --git a/tests/bookmarks_and_history/test_user_can_forget_history.py b/tests/bookmarks_and_history/test_user_can_forget_history.py index df720affb..63d6d5850 100644 --- a/tests/bookmarks_and_history/test_user_can_forget_history.py +++ b/tests/bookmarks_and_history/test_user_can_forget_history.py @@ -2,7 +2,7 @@ from selenium.webdriver import Firefox from modules.browser_object import ForgetPanel, Navigation, PanelUi, TabBar -from modules.page_object import CustomizeFirefox, GenericPage +from modules.page_object import CustomizeFirefox @pytest.fixture() @@ -10,7 +10,7 @@ def test_case(): return "174072" -links = [ +ABOUT_PAGES = [ "about:about", "about:addons", "about:cache", @@ -22,37 +22,25 @@ def test_user_can_forget_history(driver: Firefox): """ C174072: Verify that the user can Forget all the history from the last 5 minutes """ + # Instantiate objects tabs = TabBar(driver) - panel_ui = PanelUi(driver) + panel = PanelUi(driver) nav = Navigation(driver) forget_panel = ForgetPanel(driver) - gen_page = GenericPage(driver, url="https://www.google.com/") customize_firefox = CustomizeFirefox(driver) - tabs_to_open = 4 - - for i in range(tabs_to_open): - driver.get(links[i]) - tabs.new_tab_by_button() - tabs.switch_to_new_tab() - - panel_ui.open_panel_menu() - panel_ui.navigate_to_customize_toolbar() + # Add the Forget button to the toolbar + panel.open_panel_menu() + panel.navigate_to_customize_toolbar() customize_firefox.add_widget_to_toolbar("forget") - tabs.new_tab_by_button() - tabs.switch_to_new_tab() - - gen_page.open() - - with driver.context(driver.CONTEXT_CHROME): - nav.get_element("forget-button").click() - assert ( - forget_panel.get_element("forget-five-minutes").get_attribute("selected") - == "true" - ) + # Create history + tabs.open_multiple_tabs_with_pages(ABOUT_PAGES) + # Use Forget button to clear the last 5 minutes of history + nav.open_forget_panel() forget_panel.forget_history("forget-five-minutes") + # Verify history was removed tabs.switch_to_new_tab() - panel_ui.element_does_not_exist("bookmark-item") + panel.element_does_not_exist("bookmark-item") diff --git a/tests/geolocation/test_geolocation_shared_via_html5.py b/tests/geolocation/test_geolocation_shared_via_html5.py index 1289bd467..971b48337 100644 --- a/tests/geolocation/test_geolocation_shared_via_html5.py +++ b/tests/geolocation/test_geolocation_shared_via_html5.py @@ -1,3 +1,6 @@ +import sys +from os import environ + import pytest from selenium.webdriver import Firefox from selenium.webdriver.common.by import By @@ -25,6 +28,8 @@ def add_to_prefs_list(): TEST_URL = "https://browserleaks.com/geo" +WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win") + def wait_for_geolocation_data(web_page, timeout=20): """Wait until both latitude and longitude data are available.""" @@ -40,6 +45,7 @@ def wait_for_geolocation_data(web_page, timeout=20): ) +@pytest.mark.skipif(WIN_GHA, reason="Recent permission changes at their side") def test_allow_permission_on_geolocation_via_html5(driver: Firefox): """ C15189 - Verify that geolocation is successfully shared when the user allows permission via the HTML5 Geolocation API @@ -56,7 +62,7 @@ def test_allow_permission_on_geolocation_via_html5(driver: Firefox): wait_for_geolocation_data(web_page) # Allow the location sharing while choose the option Remember this decision - tabs.open_web_page_in_new_tab(web_page, num_tabs=2) + tabs.open_single_page_in_new_tab(web_page, num_tabs=2) nav.element_clickable("checkbox-remember-this-decision") nav.click_on("checkbox-remember-this-decision") nav.handle_geolocation_prompt(button_type="primary") @@ -65,12 +71,13 @@ def test_allow_permission_on_geolocation_via_html5(driver: Firefox): wait_for_geolocation_data(web_page) # Assert that the permission icon is displayed in address bar when in a new tab - tabs.open_web_page_in_new_tab(web_page, num_tabs=3) + tabs.open_single_page_in_new_tab(web_page, num_tabs=3) with driver.context(driver.CONTEXT_CHROME): permission_icon = nav.get_element("permissions-location-icon") assert permission_icon.is_displayed() +@pytest.mark.skipif(WIN_GHA, reason="Recent permission changes at their side") def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox): """ C15189 - Verify that geolocation is not shared when the user blocks permission via the HTML5 Geolocation API @@ -91,7 +98,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox): ) # Block the location sharing while choose the option Remember this decision - tabs.open_web_page_in_new_tab(web_page, num_tabs=2) + tabs.open_single_page_in_new_tab(web_page, num_tabs=2) nav.element_clickable("checkbox-remember-this-decision") nav.click_on("checkbox-remember-this-decision") nav.handle_geolocation_prompt(button_type="secondary") @@ -104,7 +111,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox): ) # Assert that the permission icon is displayed in address bar when in a new tab - tabs.open_web_page_in_new_tab(web_page, num_tabs=3) + tabs.open_single_page_in_new_tab(web_page, num_tabs=3) with driver.context(driver.CONTEXT_CHROME): permission_icon = nav.get_element("permissions-location-icon") assert permission_icon.is_displayed() diff --git a/tests/geolocation/test_geolocation_shared_via_w3c_api.py b/tests/geolocation/test_geolocation_shared_via_w3c_api.py index 2c3ad6693..4b76e4638 100644 --- a/tests/geolocation/test_geolocation_shared_via_w3c_api.py +++ b/tests/geolocation/test_geolocation_shared_via_w3c_api.py @@ -1,3 +1,6 @@ +import sys +from os import environ + import pytest from selenium.webdriver import Firefox @@ -24,6 +27,8 @@ def add_to_prefs_list(): TEST_URL = "https://www.w3schools.com/html/html5_geolocation.asp" +WIN_GHA = environ.get("GITHUB_ACTIONS") == "true" and sys.platform.startswith("win") + @pytest.fixture() def temp_selectors(): @@ -46,6 +51,7 @@ def temp_selectors(): } +@pytest.mark.skipif(WIN_GHA, reason="Recent permission changes at their side") def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selectors): """ C15186 - Verify that geolocation is successfully shared when the user allows permission via the W3C Geolocation API @@ -73,7 +79,7 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec assert web_page.get_element("location-marker").get_attribute("style") # Open a new tab, because refresh will keep the allow state of the location for one hour or until the tab is closed - tabs.open_web_page_in_new_tab(web_page, num_tabs=2) + tabs.open_single_page_in_new_tab(web_page, num_tabs=2) # Click the 'Try It' button and Allow the location sharing while choose the option Remember this decision web_page.click_on("geolocation-button-selector") @@ -85,12 +91,13 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec assert web_page.get_element("location-marker").get_attribute("style") # Assert that the permission icon is displayed in address bar when in a new tab - tabs.open_web_page_in_new_tab(web_page, num_tabs=3) + tabs.open_single_page_in_new_tab(web_page, num_tabs=3) with driver.context(driver.CONTEXT_CHROME): permission_icon = nav.get_element("permissions-location-icon") assert permission_icon.is_displayed() +@pytest.mark.skipif(WIN_GHA, reason="Recent permission changes at their side") def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selectors): """ C15186 - Verify that geolocation is not shared when the user blocks permission via the W3C Geolocation API @@ -117,7 +124,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec assert not web_page.get_element("location-marker").get_attribute("style") # Click the 'Try It' button and Block the location sharing while choose the option Remember this decision - tabs.open_web_page_in_new_tab(web_page, num_tabs=2) + tabs.open_single_page_in_new_tab(web_page, num_tabs=2) web_page.click_on("geolocation-button-selector") nav.handle_geolocation_prompt(button_type="secondary", remember_this_decision=True) @@ -126,7 +133,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec assert not web_page.get_element("location-marker").get_attribute("style") # Assert that the permission icon is displayed in address bar when in a new tab - tabs.open_web_page_in_new_tab(web_page, num_tabs=3) + tabs.open_single_page_in_new_tab(web_page, num_tabs=3) with driver.context(driver.CONTEXT_CHROME): permission_icon = nav.get_element("permissions-location-icon") assert permission_icon.is_displayed()