Skip to content

Commit c56fdd2

Browse files
authored
Merge pull request #805 from mozilla/anca/refactoring-final
Anca/ Refactoring History and Bookmark - final
2 parents 4dce9f5 + ec5d835 commit c56fdd2

10 files changed

+153
-105
lines changed

modules/browser_object_forget_panel.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55

66
class ForgetPanel(BasePage):
77
"""
8-
BOM for the forget panel
8+
BOM for the Forget Panel
99
"""
1010

1111
URL_TEMPLATE = ""
1212

13+
def select_timeframe(
14+
self,
15+
timeframe: Literal["forget-five-minutes", "forget-two-hours", "forget-one-day"],
16+
) -> "ForgetPanel":
17+
"""
18+
Select a specific timeframe option in the forget panel.
19+
This will click the option regardless of what's currently selected.
20+
21+
Argument:
22+
timeframe: Timeframe to forget. Restricted options to "forget-five-minutes",
23+
"forget-two-hours", or "forget-one-day"
24+
"""
25+
self.click_on(timeframe)
26+
return self
27+
1328
def forget_history(
1429
self,
1530
timeframe: Literal["forget-five-minutes", "forget-two-hours", "forget-one-day"],
16-
) -> BasePage:
17-
with self.driver.context(self.driver.CONTEXT_CHROME):
18-
self.get_element(timeframe).click()
19-
self.get_element("forget-confirm-button").click()
20-
return self
31+
) -> "ForgetPanel":
32+
"""
33+
Forget browsing history for a given timeframe.
34+
"""
35+
self.select_timeframe(timeframe)
36+
self.click_on("forget-confirm-button")
37+
return self

modules/browser_object_navigation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ def select_element_in_nav(self, element: str) -> BasePage:
342342
self.get_element(element).click()
343343
return self
344344

345+
@BasePage.context_chrome
346+
def open_forget_panel(self) -> BasePage:
347+
"""Open the Forget Panel by clicking the Forget button in the toolbar."""
348+
self.get_element("forget-button").click()
349+
return self
350+
345351
@BasePage.context_chrome
346352
def get_legacy_search_engine_label(self) -> str:
347353
"""Return the displayed engine name from the legacy search bar."""

modules/browser_object_tabbar.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,33 @@ def close_tab(self, tab: WebElement) -> BasePage:
283283
self.get_element("tab-x-icon", parent_element=tab).click()
284284
return self
285285

286-
def open_web_page_in_new_tab(self, web_page: BasePage, num_tabs: int) -> BasePage:
286+
def open_single_page_in_new_tab(self, page: BasePage, num_tabs: int) -> BasePage:
287287
"""
288288
Opens a new tab, switches the driver context to the new tab, and opens the given webpage
289+
Arguments:
290+
page: The page object to open in the new tab
291+
num_tabs: Expected total number of tabs after opening the new tab (used for waiting)
289292
"""
290293
self.new_tab_by_button()
291294
self.wait_for_num_tabs(num_tabs)
292295
self.driver.switch_to.window(self.driver.window_handles[-1])
293-
web_page.open()
296+
page.open()
297+
return self
298+
299+
def open_multiple_tabs_with_pages(self, pages: list) -> "TabBar":
300+
"""
301+
Opens multiple new tabs and navigates to different pages in each tab.
302+
303+
Argument:
304+
pages: List of page objects or URLs to open in separate tabs
305+
"""
306+
for page in pages:
307+
self.new_tab_by_button()
308+
self.wait_for_num_tabs(len(self.driver.window_handles))
309+
self.driver.switch_to.window(self.driver.window_handles[-1])
310+
311+
if isinstance(page, str):
312+
self.driver.get(page)
313+
else:
314+
page.open()
294315
return self

tests/bookmarks_and_history/test_deleted_page_not_remembered.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ def test_deleted_page_not_remembered(driver: Firefox, sys_platform):
1919
"""
2020
C216273: Verify that the deleted page from the Hamburger History submenu is not remembered or autofilled in the URL bar
2121
"""
22-
panel_ui = PanelUi(driver)
23-
panel_ui.open()
22+
# Instantiate objects
23+
panel = PanelUi(driver)
2424
nav = Navigation(driver)
2525
context_menu = ContextMenu(driver)
2626

27-
panel_ui.open_history_menu()
28-
panel_ui.context_click("bookmark-by-title", labels=["Firefox Privacy Notice"])
29-
27+
# Open history menu and right-click on a specific history entry and delete it
28+
panel.open_history_menu()
29+
panel.context_click("bookmark-by-title", labels=["Firefox Privacy Notice"])
3030
context_menu.click_and_hide_menu("context-menu-delete-page")
31-
nav.type_in_awesome_bar("Firefox Privacy Notice")
3231

33-
with driver.context(driver.CONTEXT_CHROME):
34-
nav.expect(lambda _: len(nav.get_elements("results-dropdown")) == 1)
32+
# Type the deleted page name in the URL bar and verify the deleted page is not suggested
33+
nav.type_in_awesome_bar("Firefox Privacy Notice")
34+
nav.expect(lambda _: len(nav.get_elements("results-dropdown")) == 1)

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

tests/bookmarks_and_history/test_import_bookmarks_edge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from selenium.webdriver import Firefox
77

8-
from modules.browser_object_navigation import Navigation
8+
from modules.browser_object import Navigation
99
from modules.page_object import AboutPrefs
1010

1111
NEWS_ARTICLE_TITLE = "Level 1, 2 evacuations issued for fire burning in Chelan"

tests/bookmarks_and_history/test_opened_website_in_new_tab_present_in_hamburger_history_menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_the_website_opened_in_new_tab_is_present_in_history_menu(driver: Firefo
2929
panel = PanelUi(driver)
3030

3131
# Open a desired webpage in a new tab
32-
tabs.open_web_page_in_new_tab(page, 2)
32+
tabs.open_single_page_in_new_tab(page, 2)
3333
page.url_contains("wikipedia")
3434

3535
# Verify the opened webpage from last step is present in the Hamburger Menu, History section and is on top of the

tests/bookmarks_and_history/test_user_can_forget_history.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
from selenium.webdriver import Firefox
33

44
from modules.browser_object import ForgetPanel, Navigation, PanelUi, TabBar
5-
from modules.page_object import CustomizeFirefox, GenericPage
5+
from modules.page_object import CustomizeFirefox
66

77

88
@pytest.fixture()
99
def test_case():
1010
return "174072"
1111

1212

13-
links = [
13+
ABOUT_PAGES = [
1414
"about:about",
1515
"about:addons",
1616
"about:cache",
@@ -22,37 +22,25 @@ def test_user_can_forget_history(driver: Firefox):
2222
"""
2323
C174072: Verify that the user can Forget all the history from the last 5 minutes
2424
"""
25+
# Instantiate objects
2526
tabs = TabBar(driver)
26-
panel_ui = PanelUi(driver)
27+
panel = PanelUi(driver)
2728
nav = Navigation(driver)
2829
forget_panel = ForgetPanel(driver)
29-
gen_page = GenericPage(driver, url="https://www.google.com/")
3030
customize_firefox = CustomizeFirefox(driver)
3131

32-
tabs_to_open = 4
33-
34-
for i in range(tabs_to_open):
35-
driver.get(links[i])
36-
tabs.new_tab_by_button()
37-
tabs.switch_to_new_tab()
38-
39-
panel_ui.open_panel_menu()
40-
panel_ui.navigate_to_customize_toolbar()
32+
# Add the Forget button to the toolbar
33+
panel.open_panel_menu()
34+
panel.navigate_to_customize_toolbar()
4135
customize_firefox.add_widget_to_toolbar("forget")
4236

43-
tabs.new_tab_by_button()
44-
tabs.switch_to_new_tab()
45-
46-
gen_page.open()
47-
48-
with driver.context(driver.CONTEXT_CHROME):
49-
nav.get_element("forget-button").click()
50-
assert (
51-
forget_panel.get_element("forget-five-minutes").get_attribute("selected")
52-
== "true"
53-
)
37+
# Create history
38+
tabs.open_multiple_tabs_with_pages(ABOUT_PAGES)
5439

40+
# Use Forget button to clear the last 5 minutes of history
41+
nav.open_forget_panel()
5542
forget_panel.forget_history("forget-five-minutes")
5643

44+
# Verify history was removed
5745
tabs.switch_to_new_tab()
58-
panel_ui.element_does_not_exist("bookmark-item")
46+
panel.element_does_not_exist("bookmark-item")

0 commit comments

Comments
 (0)