Skip to content

Commit

Permalink
fix bookmark test issues (#330)
Browse files Browse the repository at this point in the history
* fix bookmark test issues

* fix additional broken tests

* fix additional broken tests

* fails in mac gha

* fix about config json

* fix xfail condition
  • Loading branch information
ben-c-at-moz authored Nov 16, 2024
1 parent fbb5123 commit 7339069
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
1 change: 1 addition & 0 deletions modules/data/about_config.components.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@
"selectorData": "changemp",
"strategy": "id",
"groups": []
}
}
8 changes: 6 additions & 2 deletions modules/page_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def opposite_context(self):
else self.driver.CONTEXT_CHROME
)

def is_private(self):
"""Determine if current browsing context is private"""
with self.driver.context(self.driver.CONTEXT_CHROME):
return "Private Browsing" in self.driver.title

def custom_wait(self, **kwargs) -> WebDriverWait:
"""
Create a custom WebDriverWait object, refer to Selenium docs
Expand Down Expand Up @@ -671,8 +676,7 @@ def wait_for_num_tabs(self, num_tabs: int) -> Page:

def switch_to_new_tab(self) -> Page:
"""Get list of all window handles, switch to the newly opened tab"""
handles = self.driver.window_handles
self.driver.switch_to.window(handles[-1])
self.driver.switch_to.window(self.driver.window_handles[-1])
return self

def wait_for_num_windows(self, num: int) -> Page:
Expand Down
25 changes: 2 additions & 23 deletions tests/bookmarks_and_history/test_deleted_page_not_remembered.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import logging
import platform
from os import environ

import pytest
from selenium.webdriver import Firefox

from modules.browser_object import ContextMenu, Navigation, PanelUi

X_PADDING = 50
if (
platform.system().lower().startswith("win")
and environ.get("GITHUB_ACTIONS") == "true"
):
X_PADDING += 25


@pytest.fixture()
def test_case():
Expand All @@ -25,6 +14,7 @@ def use_profile():
return "theme_change"


@pytest.mark.headed
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
Expand All @@ -35,18 +25,7 @@ def test_deleted_page_not_remembered(driver: Firefox, sys_platform):
context_menu = ContextMenu(driver)

panel_ui.open_history_menu()
history_items = panel_ui.get_all_history()

firefox_privacy_notice = history_items[-1]
with driver.context(driver.CONTEXT_CHROME):
x_offset = firefox_privacy_notice.size.get("width") + X_PADDING
logging.info(x_offset)
if sys_platform.lower() == "linux":
panel_ui.click_on(firefox_privacy_notice)
else:
panel_ui.actions.move_to_element_with_offset(
firefox_privacy_notice, x_offset, 0
).click().perform()
panel_ui.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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import platform
from os import environ

import pytest
from selenium.webdriver import Firefox

Expand All @@ -13,6 +16,10 @@ def test_case():
URL_TO_BOOKMARK = "https://www.mozilla.org/"


@pytest.mark.xfail(
platform.system() == "Darwin" and environ.get("GITHUB_ACTIONS") == "true",
reason="Test failing in Mac GHA",
)
def test_open_bookmark_in_new_window_via_toolbar_context_menu(driver: Firefox):
"""
C2084552: Verify that a bookmarked page can be open in a New Window from Toolbar context menu.
Expand All @@ -35,9 +42,10 @@ def test_open_bookmark_in_new_window_via_toolbar_context_menu(driver: Firefox):
"bookmark-by-title", labels=["Internet for people"]
)
context_menu.context_click(bookmarked_page)
context_menu.get_element("context-menu-toolbar-open-in-new-window").click()
context_menu.click_and_hide_menu("context-menu-toolbar-open-in-new-window")

# Verify that the test page is opened in a new normal window
driver.switch_to.window(driver.window_handles[-1])
nav.element_not_visible("private-browsing-icon")
assert not nav.is_private()

page.url_contains("mozilla")
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import platform
from os import environ

import pytest
from selenium.webdriver import Firefox

Expand All @@ -13,6 +16,10 @@ def test_case():
URL_TO_BOOKMARK = "https://www.mozilla.org/"


@pytest.mark.xfail(
platform.system() == "Darwin" and environ.get("GITHUB_ACTIONS") == "true",
reason="Test failing in Mac GHA",
)
def test_open_bookmark_in_new_private_window_via_toolbar_context_menu(driver: Firefox):
"""
C2084553: Verify that a bookmarked page can be open in a New Private Window from Toolbar context menu.
Expand All @@ -36,11 +43,12 @@ def test_open_bookmark_in_new_private_window_via_toolbar_context_menu(driver: Fi
"bookmark-by-title", labels=["Internet for people"]
)
context_menu.context_click(bookmarked_page)
context_menu.get_element(
context_menu.click_and_hide_menu(
"context-menu-toolbar-open-in-new-private-window"
).click()
)

# Verify that the test page is opened in a new private window
driver.switch_to.window(driver.window_handles[-1])
nav.element_visible("private-browsing-icon")
assert nav.is_private()

page.url_contains("mozilla")
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def test_undo_close_tab_private_browsing(driver: Firefox, sys_platform: str):
tabs.reopen_closed_tab_by_keys(sys_platform)
tabs.wait_for_num_tabs(2)
tabs.switch_to_new_tab()
logging.info(f"The observed title in the chrome context is {driver.title}")
tabs.title_contains("Private Browsing")
assert nav.is_private()

logging.info(f"The observed title in the content context is {driver.title}")
generic_page.title_contains("About About")
generic_page.url_contains("about:about")

0 comments on commit 7339069

Please sign in to comment.