Skip to content

Commit

Permalink
Merge pull request #344 from mozilla/vs/test-default-zoom-persists
Browse files Browse the repository at this point in the history
vs/test-default-zoom
  • Loading branch information
vsangereanMOZ authored Nov 22, 2024
2 parents 09f0d39 + 712f88b commit 0fd1f94
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
14 changes: 14 additions & 0 deletions SELECTOR_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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
```
#### about_profiles
```
Selector Name: profile-container
Expand Down
13 changes: 13 additions & 0 deletions modules/data/about_prefs.components.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,5 +572,18 @@
"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": "menuitem[data-l10n-id='preferences-default-zoom-value'][value='{.*}']",
"strategy": "css",
"groups": []
}

}
10 changes: 10 additions & 0 deletions modules/page_object_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ def select_https_only_setting(self, option_id: HttpsOnlyStatus) -> BasePage:
self.element_attribute_contains(option_id, "selected", "true")
return self

def set_default_zoom_level(self, zoom_percentage: int) -> BasePage:
"""
Sets the Default Zoom level in about:preferences.
"""
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


class AboutAddons(BasePage):
"""
Expand Down
74 changes: 74 additions & 0 deletions tests/scrolling_panning_zooming/test_default_zoom_persists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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):
"""
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 <div>
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: 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, load the test URL, and verify the <div>'s position
tabs = TabBar(driver)

# 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

# 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 <div> 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}")

# 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}"
)

# Set the zoomed position for consistency checks if it's the first tab
if zoomed_position is None:
zoomed_position = current_position

# 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}"
)
1 change: 1 addition & 0 deletions tests/scrolling_panning_zooming/test_zoom_from_menu_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0fd1f94

Please sign in to comment.