Skip to content

Commit 68f116b

Browse files
committed
Add refactored test 174072
1 parent b74e615 commit 68f116b

7 files changed

+75
-41
lines changed

modules/browser_object_forget_panel.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
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+
@BasePage.context_chrome
14+
def select_timeframe(
15+
self,
16+
timeframe: Literal["forget-five-minutes", "forget-two-hours", "forget-one-day"],
17+
) -> "ForgetPanel":
18+
"""
19+
Select a specific timeframe option in the forget panel.
20+
This will click the option regardless of what's currently selected.
21+
22+
Argument:
23+
timeframe: Timeframe to forget. Restricted options to "forget-five-minutes",
24+
"forget-two-hours", or "forget-one-day"
25+
"""
26+
self.click_on(timeframe)
27+
return self
28+
29+
@BasePage.context_chrome
1330
def forget_history(
1431
self,
1532
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
33+
) -> "ForgetPanel":
34+
"""
35+
Forget browsing history for a given timeframe.
36+
"""
37+
self.select_timeframe(timeframe)
38+
self.click_on("forget-confirm-button")
39+
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_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: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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")

tests/geolocation/test_geolocation_shared_via_html5.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_allow_permission_on_geolocation_via_html5(driver: Firefox):
5656
wait_for_geolocation_data(web_page)
5757

5858
# Allow the location sharing while choose the option Remember this decision
59-
tabs.open_web_page_in_new_tab(web_page, num_tabs=2)
59+
tabs.open_single_page_in_new_tab(web_page, num_tabs=2)
6060
nav.element_clickable("checkbox-remember-this-decision")
6161
nav.click_on("checkbox-remember-this-decision")
6262
nav.handle_geolocation_prompt(button_type="primary")
@@ -65,7 +65,7 @@ def test_allow_permission_on_geolocation_via_html5(driver: Firefox):
6565
wait_for_geolocation_data(web_page)
6666

6767
# Assert that the permission icon is displayed in address bar when in a new tab
68-
tabs.open_web_page_in_new_tab(web_page, num_tabs=3)
68+
tabs.open_single_page_in_new_tab(web_page, num_tabs=3)
6969
with driver.context(driver.CONTEXT_CHROME):
7070
permission_icon = nav.get_element("permissions-location-icon")
7171
assert permission_icon.is_displayed()
@@ -91,7 +91,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox):
9191
)
9292

9393
# Block the location sharing while choose the option Remember this decision
94-
tabs.open_web_page_in_new_tab(web_page, num_tabs=2)
94+
tabs.open_single_page_in_new_tab(web_page, num_tabs=2)
9595
nav.element_clickable("checkbox-remember-this-decision")
9696
nav.click_on("checkbox-remember-this-decision")
9797
nav.handle_geolocation_prompt(button_type="secondary")
@@ -104,7 +104,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox):
104104
)
105105

106106
# Assert that the permission icon is displayed in address bar when in a new tab
107-
tabs.open_web_page_in_new_tab(web_page, num_tabs=3)
107+
tabs.open_single_page_in_new_tab(web_page, num_tabs=3)
108108
with driver.context(driver.CONTEXT_CHROME):
109109
permission_icon = nav.get_element("permissions-location-icon")
110110
assert permission_icon.is_displayed()

tests/geolocation/test_geolocation_shared_via_w3c_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec
7373
assert web_page.get_element("location-marker").get_attribute("style")
7474

7575
# Open a new tab, because refresh will keep the allow state of the location for one hour or until the tab is closed
76-
tabs.open_web_page_in_new_tab(web_page, num_tabs=2)
76+
tabs.open_single_page_in_new_tab(web_page, num_tabs=2)
7777

7878
# Click the 'Try It' button and Allow the location sharing while choose the option Remember this decision
7979
web_page.click_on("geolocation-button-selector")
@@ -85,7 +85,7 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec
8585
assert web_page.get_element("location-marker").get_attribute("style")
8686

8787
# Assert that the permission icon is displayed in address bar when in a new tab
88-
tabs.open_web_page_in_new_tab(web_page, num_tabs=3)
88+
tabs.open_single_page_in_new_tab(web_page, num_tabs=3)
8989
with driver.context(driver.CONTEXT_CHROME):
9090
permission_icon = nav.get_element("permissions-location-icon")
9191
assert permission_icon.is_displayed()
@@ -117,7 +117,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec
117117
assert not web_page.get_element("location-marker").get_attribute("style")
118118

119119
# Click the 'Try It' button and Block the location sharing while choose the option Remember this decision
120-
tabs.open_web_page_in_new_tab(web_page, num_tabs=2)
120+
tabs.open_single_page_in_new_tab(web_page, num_tabs=2)
121121
web_page.click_on("geolocation-button-selector")
122122
nav.handle_geolocation_prompt(button_type="secondary", remember_this_decision=True)
123123

@@ -126,7 +126,7 @@ def test_block_permission_on_geolocation_via_w3c_api(driver: Firefox, temp_selec
126126
assert not web_page.get_element("location-marker").get_attribute("style")
127127

128128
# Assert that the permission icon is displayed in address bar when in a new tab
129-
tabs.open_web_page_in_new_tab(web_page, num_tabs=3)
129+
tabs.open_single_page_in_new_tab(web_page, num_tabs=3)
130130
with driver.context(driver.CONTEXT_CHROME):
131131
permission_icon = nav.get_element("permissions-location-icon")
132132
assert permission_icon.is_displayed()

0 commit comments

Comments
 (0)