From 5a69d6f3e362d70565678f086e2285572d13c920 Mon Sep 17 00:00:00 2001 From: "virgil.sangerean" Date: Thu, 21 Nov 2024 17:14:28 +0200 Subject: [PATCH 1/5] vs/test-default-zoom --- modules/data/about_prefs.components.json | 12 +++++ modules/page_object_prefs.py | 21 ++++++++ .../test_default_zoom_persists.py | 51 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 tests/scrolling_panning_zooming/test_default_zoom_persists.py diff --git a/modules/data/about_prefs.components.json b/modules/data/about_prefs.components.json index e194d8ba..d1deec94 100644 --- a/modules/data/about_prefs.components.json +++ b/modules/data/about_prefs.components.json @@ -572,5 +572,17 @@ "selectorData": "richlistitem[origin='https://www.mlb.com'] menulist[label='Allow Audio and Video']", "strategy": "css", "groups": [] + }, + + "default-zoom-dropdown": { + "selectorData": "defaultZoom", + "strategy": "id", + "groups": [] + }, + + "default-zoom-dropdown-value": { + "selectorData": "preferences-default-zoom-value", + "strategy": "id", + "groups": [] } } diff --git a/modules/page_object_prefs.py b/modules/page_object_prefs.py index e64951c3..dc0f6100 100644 --- a/modules/page_object_prefs.py +++ b/modules/page_object_prefs.py @@ -400,6 +400,27 @@ def select_https_only_setting(self, option_id: HttpsOnlyStatus) -> BasePage: self.element_attribute_contains(option_id, "selected", "true") return self + def set_default_zoom(self, zoom_percentage: int) -> BasePage: + """ + Sets the Default Zoom level in about:preferences. + """ + + # Navigate to the zoom settings section + self.find_in_settings("Default zoom") + + # Locate the dropdown or input field for Default Zoom + zoom_dropdown = self.get_element("default-zoom-dropdown") + + # Open the dropdown menu + zoom_dropdown.click() + + # Select the desired zoom percentage + zoom_option = self.get_element("default-zoom-dropdown-value", + labels=[f"{zoom_percentage}%"]) + zoom_option.click() + + return self + class AboutAddons(BasePage): """ diff --git a/tests/scrolling_panning_zooming/test_default_zoom_persists.py b/tests/scrolling_panning_zooming/test_default_zoom_persists.py new file mode 100644 index 00000000..50056667 --- /dev/null +++ b/tests/scrolling_panning_zooming/test_default_zoom_persists.py @@ -0,0 +1,51 @@ +import logging +import pytest + +from selenium.webdriver import Firefox +from modules.page_object_generics import GenericPage +from modules.page_object import AboutPrefs +from modules.browser_object import TabBar + +@pytest.fixture() +def test_case(): + return "545730" + +def test_default_zoom_across_tabs(driver: Firefox): + """ + This test verifies that the default zoom level is correctly set to 150% + and persists across multiple tabs. + """ + + # Step 1: Open the browser and navigate to about:preferences + about_prefs = AboutPrefs(driver, category="general").open() + + # Step 2: Set the default zoom level to 150% + about_prefs.set_default_zoom(150) + + # Step 3: Open three tabs of the same website + tabs = TabBar(driver) + test_url = "https://www.example.com" + + # Open the first tab and load the URL + page = GenericPage(driver, url=test_url) + page.open() + + + # Open two additional tabs + for _ in range(2): + tabs.new_tab_by_button() + driver.switch_to.window(driver.window_handles[-1]) # Switch to the newly opened tab + page = GenericPage(driver, url=test_url) + page.open() + + # Step 4: Verify the default zoom level in each tab + for index, handle in enumerate(driver.window_handles, start=1): + driver.switch_to.window(handle) + + # Verify the default zoom level + with driver.context(driver.CONTEXT_CHROME): + zoom_level_indicator = about_prefs.get_element("toolbar-zoom-level") + zoom_level = zoom_level_indicator.get_attribute("label") + logging.info(f"Zoom level in tab {index}: {zoom_level}") + + assert zoom_level == "150%", f"Default zoom level in tab {index} is {zoom_level}, expected '150%'" From b65432d7e39969722c7a3e34c7ae0e8d4097a4ed Mon Sep 17 00:00:00 2001 From: "virgil.sangerean" Date: Thu, 21 Nov 2024 17:14:28 +0200 Subject: [PATCH 2/5] vs/test-default-zoom --- SELECTOR_INFO.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SELECTOR_INFO.md b/SELECTOR_INFO.md index c686347d..78e43efb 100644 --- a/SELECTOR_INFO.md +++ b/SELECTOR_INFO.md @@ -1067,6 +1067,20 @@ Description: mlb website autoplay settings Location: about:preferences#privacy - Autoplay settings Path to .json: modules/data/about_prefs.components.json ``` +``` +Selector Name: default-zoom-dropdown +Selector Data: defaultZoom +Description: The default zoom dropdown. +Location: about:preferences - Zoom settings +Path to .json: modules/data/about_prefs.components.json +``` +``` +Selector Name: default-zoom-dropdown-value +Selector Data: preferences-default-zoom-value +Description: The dropdown menu for default zoom selection +Location: about:preferences - Zoom settings +Path to .json: modules/data/about_prefs.components.json +``` #### about_profiles ``` Selector Name: profile-container From 993b59b7e163378a4c1158bd6b35f664dee3fcfe Mon Sep 17 00:00:00 2001 From: whlpatricia Date: Thu, 21 Nov 2024 16:43:40 -0500 Subject: [PATCH 3/5] completed set default zoom function --- SELECTOR_INFO.md | 2 +- modules/data/about_prefs.components.json | 5 +++-- modules/page_object_prefs.py | 21 +++++-------------- .../test_default_zoom_persists.py | 2 +- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/SELECTOR_INFO.md b/SELECTOR_INFO.md index 59a9a1ee..ee02b488 100644 --- a/SELECTOR_INFO.md +++ b/SELECTOR_INFO.md @@ -1076,7 +1076,7 @@ Path to .json: modules/data/about_prefs.components.json ``` ``` Selector Name: default-zoom-dropdown-value -Selector Data: preferences-default-zoom-value +Selector Data: menuitem[data-l10n-id='preferences-default-zoom-value'][value='{.*}'] Description: The dropdown menu for default zoom selection Location: about:preferences - Zoom settings Path to .json: modules/data/about_prefs.components.json diff --git a/modules/data/about_prefs.components.json b/modules/data/about_prefs.components.json index d1deec94..2adb4fad 100644 --- a/modules/data/about_prefs.components.json +++ b/modules/data/about_prefs.components.json @@ -581,8 +581,9 @@ }, "default-zoom-dropdown-value": { - "selectorData": "preferences-default-zoom-value", - "strategy": "id", + "selectorData": "menuitem[data-l10n-id='preferences-default-zoom-value'][value='{.*}']", + "strategy": "css", "groups": [] } + } diff --git a/modules/page_object_prefs.py b/modules/page_object_prefs.py index 0b091d80..b705efea 100644 --- a/modules/page_object_prefs.py +++ b/modules/page_object_prefs.py @@ -403,25 +403,14 @@ def select_https_only_setting(self, option_id: HttpsOnlyStatus) -> BasePage: self.element_attribute_contains(option_id, "selected", "true") return self - def set_default_zoom(self, zoom_percentage: int) -> BasePage: + def set_default_zoom_level(self, zoom_percentage: int) -> BasePage: """ Sets the Default Zoom level in about:preferences. """ - - # Navigate to the zoom settings section - self.find_in_settings("Default zoom") - - # Locate the dropdown or input field for Default Zoom - zoom_dropdown = self.get_element("default-zoom-dropdown") - - # Open the dropdown menu - zoom_dropdown.click() - - # Select the desired zoom percentage - zoom_option = self.get_element("default-zoom-dropdown-value", - labels=[f"{zoom_percentage}%"]) - zoom_option.click() - + self.click_on("default-zoom-dropdown") + with self.driver.context(self.driver.CONTEXT_CHROME): + self.click_on("default-zoom-dropdown-value", labels=[f"{zoom_percentage}"]) + self.click_on("default-zoom-dropdown") return self diff --git a/tests/scrolling_panning_zooming/test_default_zoom_persists.py b/tests/scrolling_panning_zooming/test_default_zoom_persists.py index 50056667..4a006fe6 100644 --- a/tests/scrolling_panning_zooming/test_default_zoom_persists.py +++ b/tests/scrolling_panning_zooming/test_default_zoom_persists.py @@ -20,7 +20,7 @@ def test_default_zoom_across_tabs(driver: Firefox): about_prefs = AboutPrefs(driver, category="general").open() # Step 2: Set the default zoom level to 150% - about_prefs.set_default_zoom(150) + about_prefs.set_default_zoom_level(150) # Step 3: Open three tabs of the same website tabs = TabBar(driver) From 79bd0ae8ab85343a06ee97d535d7f4e489c2dc91 Mon Sep 17 00:00:00 2001 From: "virgil.sangerean" Date: Fri, 22 Nov 2024 11:09:49 +0200 Subject: [PATCH 4/5] vs/test-default-zoom --- .../test_default_zoom_persists.py | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/tests/scrolling_panning_zooming/test_default_zoom_persists.py b/tests/scrolling_panning_zooming/test_default_zoom_persists.py index 4a006fe6..60cefd6b 100644 --- a/tests/scrolling_panning_zooming/test_default_zoom_persists.py +++ b/tests/scrolling_panning_zooming/test_default_zoom_persists.py @@ -1,51 +1,75 @@ import logging +import time + import pytest from selenium.webdriver import Firefox +from selenium.webdriver.common.by import By + from modules.page_object_generics import GenericPage from modules.page_object import AboutPrefs from modules.browser_object import TabBar + @pytest.fixture() def test_case(): return "545730" + def test_default_zoom_across_tabs(driver: Firefox): """ - This test verifies that the default zoom level is correctly set to 150% - and persists across multiple tabs. + This test verifies the following: + 1. The initial X-coordinate of a
element on the test page before setting zoom to 150%. + 2. After setting the zoom level to 150%, verifies that the X-coordinate changes and is consistent across tabs. """ - # Step 1: Open the browser and navigate to about:preferences - about_prefs = AboutPrefs(driver, category="general").open() + # Step 1: Open the test page and record the initial position of the
+ test_url = "https://www.example.com" + page = GenericPage(driver, url=test_url) + page.open() + + div = driver.find_element(By.TAG_NAME, "div") + initial_position = div.location["x"] + logging.info(f"Initial X position of div before setting zoom: {initial_position}") - # Step 2: Set the default zoom level to 150% + # Step 2: Open the browser preferences and set the default zoom level to 150% + about_prefs = AboutPrefs(driver, category="general").open() about_prefs.set_default_zoom_level(150) - # Step 3: Open three tabs of the same website + # Step 3: Open three tabs, load the test URL, and verify the
's position tabs = TabBar(driver) - test_url = "https://www.example.com" - # Open the first tab and load the URL - page = GenericPage(driver, url=test_url) - page.open() + # Store the first tab's position after zoom change for consistency checks + zoomed_position = None + for index in range(3): + # Open a new tab if not the first iteration + if index > 0: + tabs.new_tab_by_button() + driver.switch_to.window(driver.window_handles[-1]) # Switch to the newly opened tab - # Open two additional tabs - for _ in range(2): - tabs.new_tab_by_button() - driver.switch_to.window(driver.window_handles[-1]) # Switch to the newly opened tab + # Load the test URL in the current tab page = GenericPage(driver, url=test_url) page.open() + time.sleep(1) # Allow time for the page to load + + # Locate the main
element and get its X position + div = driver.find_element(By.TAG_NAME, "div") + current_position = div.location["x"] + logging.info(f"X position of div in tab {index + 1}: {current_position}") - # Step 4: Verify the default zoom level in each tab - for index, handle in enumerate(driver.window_handles, start=1): - driver.switch_to.window(handle) + # Assert that the current position is different from the initial position + assert current_position != initial_position, ( + f"Expected X position in tab {index + 1} to differ from the initial position " + f"({initial_position}), but got {current_position}" + ) - # Verify the default zoom level - with driver.context(driver.CONTEXT_CHROME): - zoom_level_indicator = about_prefs.get_element("toolbar-zoom-level") - zoom_level = zoom_level_indicator.get_attribute("label") - logging.info(f"Zoom level in tab {index}: {zoom_level}") + # Set the zoomed position for consistency checks if it's the first tab + if zoomed_position is None: + zoomed_position = current_position - assert zoom_level == "150%", f"Default zoom level in tab {index} is {zoom_level}, expected '150%'" + # Assert that the X-coordinate remains consistent across tabs + assert current_position == zoomed_position, ( + f"Expected X position in tab {index + 1} to be {zoomed_position}, " + f"but got {current_position}" + ) From c3e7115f14c6862487fbd130876c0f55f762392c Mon Sep 17 00:00:00 2001 From: "virgil.sangerean" Date: Fri, 22 Nov 2024 12:57:45 +0200 Subject: [PATCH 5/5] vs/test-default-zoom --- .../scrolling_panning_zooming/test_default_zoom_persists.py | 5 ++--- tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/scrolling_panning_zooming/test_default_zoom_persists.py b/tests/scrolling_panning_zooming/test_default_zoom_persists.py index 60cefd6b..64e63946 100644 --- a/tests/scrolling_panning_zooming/test_default_zoom_persists.py +++ b/tests/scrolling_panning_zooming/test_default_zoom_persists.py @@ -18,9 +18,8 @@ def test_case(): def test_default_zoom_across_tabs(driver: Firefox): """ - This test verifies the following: - 1. The initial X-coordinate of a
element on the test page before setting zoom to 150%. - 2. After setting the zoom level to 150%, verifies that the X-coordinate changes and is consistent across tabs. + Verify that the default zoom persists on different tabs by setting the zoom level + to 150% and that the X-coordinate changes and is consistent across tabs. """ # Step 1: Open the test page and record the initial position of the
diff --git a/tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py b/tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py index 32181b6f..9aeabcea 100644 --- a/tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py +++ b/tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py @@ -17,6 +17,7 @@ def test_case(): TEST_PAGE = "https://www.example.com" +@pytest.mark.unstable @pytest.mark.skipif(platform.system() == "Darwin", reason="Cannot access menubar in MacOS")