Skip to content

Commit 857ce35

Browse files
committed
Add refactored test 118799
1 parent f31101b commit 857ce35

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed

tests/bookmarks_and_history/test_history_menu_from_different_places.py

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from modules.browser_object_navigation import Navigation
88
from modules.browser_object_panel_ui import PanelUi
99
from modules.browser_object_tabbar import TabBar
10+
from modules.page_base import BasePage
1011
from modules.page_object_customize_firefox import CustomizeFirefox
1112

1213

@@ -15,11 +16,15 @@ def test_case():
1516
return "118799"
1617

1718

19+
# Single-use helper kept in test file (YAGNI). Avoids duplication and/or overengineering
20+
@BasePage.context_chrome
1821
def assert_elements_visibility(ui_object, elements: dict, source: str):
19-
"""Helper function to assert visibility of elements in a given UI source."""
22+
"""
23+
Helper function to assert visibility of elements in a given UI source.
24+
"""
2025
for name, locator in elements.items():
2126
element = ui_object.get_element(locator)
22-
assert element.is_displayed(), f"{name} should be visible in {source}"
27+
assert element.is_displayed()
2328

2429

2530
def test_history_menu_in_different_places(driver: Firefox):
@@ -28,77 +33,74 @@ def test_history_menu_in_different_places(driver: Firefox):
2833
Toolbar)
2934
"""
3035

31-
# 1. History options from Hamburger Menu
32-
panel_ui = PanelUi(driver)
33-
panel_ui.open_history_menu()
34-
35-
with driver.context(driver.CONTEXT_CHROME):
36-
hamburger_menu_elements = {
37-
"Back Button": "history-back-button",
38-
"History Title": "history_title",
39-
"Recently Closed Tabs": "panel-ui-history-recently-closed",
40-
"Recently Closed Windows": "recently_closed_windows",
41-
"Search History": "search_history",
42-
"Clear Recent History": "clear-recent-history",
43-
"Recent History": "recent_history",
44-
"Manage History": "manage_history",
45-
}
46-
assert_elements_visibility(panel_ui, hamburger_menu_elements, "Hamburger Menu")
47-
48-
# 2. History options from Menu Bar
36+
# 1. Verify History options from Hamburger Menu
37+
panel = PanelUi(driver)
38+
panel.open_history_menu()
39+
40+
hamburger_menu_elements = {
41+
"Back Button": "history-back-button",
42+
"History Title": "history_title",
43+
"Recently Closed Tabs": "panel-ui-history-recently-closed",
44+
"Recently Closed Windows": "recently_closed_windows",
45+
"Search History": "search_history",
46+
"Clear Recent History": "clear-recent-history",
47+
"Recent History": "recent_history",
48+
"Manage History": "manage_history",
49+
}
50+
assert_elements_visibility(panel, hamburger_menu_elements, "Hamburger Menu")
51+
52+
# 2. Verify History options from Menu Bar
4953
menu_bar = MenuBar(driver)
5054

5155
if platform.system() != "Darwin":
5256
menu_bar.open_menu("History")
5357

54-
with driver.context(driver.CONTEXT_CHROME):
55-
menu_bar_elements = {
56-
"Show All History": "menu-bar-show-all-history",
57-
"Clear Recent History": "menu-bar-clear-recent-history",
58-
"Restore Previous Session": "menu-bar-restore-previous-session",
59-
"Search History": "menu-bar-search-history",
60-
"Recently Closed Tabs": "menu-bar-recently-closed-tabs",
61-
"Recently Closed Windows": "menu-bar-recently-closed-windows",
62-
}
63-
assert_elements_visibility(menu_bar, menu_bar_elements, "Menu Bar")
58+
menu_bar_elements = {
59+
"Show All History": "menu-bar-show-all-history",
60+
"Clear Recent History": "menu-bar-clear-recent-history",
61+
"Restore Previous Session": "menu-bar-restore-previous-session",
62+
"Search History": "menu-bar-search-history",
63+
"Recently Closed Tabs": "menu-bar-recently-closed-tabs",
64+
"Recently Closed Windows": "menu-bar-recently-closed-windows",
65+
}
66+
assert_elements_visibility(menu_bar, menu_bar_elements, "Menu Bar")
6467
else:
6568
print("Skipping Menu Bar verification on macOS")
6669

67-
# 3. History options from Toolbar (History and Library)
70+
# 3. Verify History options from Toolbar (History and Library)
6871
customize_firefox = CustomizeFirefox(driver)
6972
tabs = TabBar(driver)
7073
nav = Navigation(driver)
7174

72-
panel_ui.navigate_to_customize_toolbar()
75+
panel.navigate_to_customize_toolbar()
7376
customize_firefox.add_widget_to_toolbar("history")
7477

7578
tabs.new_tab_by_button()
7679
tabs.switch_to_new_tab()
7780

78-
with driver.context(driver.CONTEXT_CHROME):
79-
nav.click_on("history-button")
81+
nav.click_on("history-button")
8082

81-
history_toolbar_elements = {
82-
"Recently Closed Tabs": "toolbar-history-recently-closed-tabs",
83-
"Recently Closed Windows": "toolbar-history-recently-closed-windows",
84-
"Search History": "toolbar-history-search-history",
85-
"Clear Recent History": "toolbar-history-clear-recent-history",
86-
"Recent History": "toolbar-history-recent_history",
87-
"Manage History": "toolbar-history-manage_history",
88-
}
89-
assert_elements_visibility(nav, history_toolbar_elements, "Toolbar History")
83+
history_toolbar_elements = {
84+
"Recently Closed Tabs": "toolbar-history-recently-closed-tabs",
85+
"Recently Closed Windows": "toolbar-history-recently-closed-windows",
86+
"Search History": "toolbar-history-search-history",
87+
"Clear Recent History": "toolbar-history-clear-recent-history",
88+
"Recent History": "toolbar-history-recent_history",
89+
"Manage History": "toolbar-history-manage_history",
90+
}
91+
assert_elements_visibility(nav, history_toolbar_elements, "Toolbar History")
9092

91-
panel_ui.open_panel_menu()
92-
panel_ui.navigate_to_customize_toolbar()
93-
customize_firefox.add_widget_to_toolbar("library")
93+
panel.open_panel_menu()
94+
panel.navigate_to_customize_toolbar()
95+
customize_firefox.add_widget_to_toolbar("library")
9496

95-
tabs.new_tab_by_button()
96-
tabs.switch_to_new_tab()
97+
tabs.new_tab_by_button()
98+
tabs.switch_to_new_tab()
9799

98-
nav.click_on("library-button")
99-
nav.click_on("library-history-submenu-button")
100+
nav.click_on("library-button")
101+
nav.click_on("library-history-submenu-button")
100102

101-
library_toolbar_elements = (
102-
history_toolbar_elements # Reuse the same locators from a different path
103-
)
104-
assert_elements_visibility(nav, library_toolbar_elements, "Toolbar Library")
103+
library_toolbar_elements = (
104+
history_toolbar_elements # Reuse the same locators from a different path
105+
)
106+
assert_elements_visibility(nav, library_toolbar_elements, "Toolbar Library")

0 commit comments

Comments
 (0)